0

I am writing a code that will hopefully be able to click on a defined button on a pop-up window. The pop-up window appears only after having clicked somewhere else (this part is working).

here's the code:

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC

from selenium.common.exceptions import TimeoutException

from selenium.webdriver.common.by import By

wait = WebDriverWait(driver, 2)
wait.until(EC.element_to_be_clickable((By.XPATH, '//button\[text()="OK"\]')))
wait.until(ExpectedConditions.visibilityOfElementLocated(By.XPATH, '//button\[text()="OK"\]'))
wait.until(ExpectedConditions.elementToBeClickable(By.XPATH, '//button\[text()="OK"\]'))
driver.findElement(By.XPATH, '//button\[text()="OK"\]').click()

I am getting an error "TimeoutException". Anyone able to fix that?

thanks a lot

5
  • 1
    You are mixing here python, java... We need to see the page you working on and all your code to understand more. But seems the text is not exactly "OK" or maybe the element is not accessible. Commented Jan 11, 2023 at 10:07
  • thank you Prophet and sorry for my mistakes. I am still very limited with my python competences. Before that, there are only few rows that define the URL and the buttons that need to be clicked. submit_button = driver.find_element(By.XPATH, '//button[text()="Open"]').click() Commented Jan 11, 2023 at 10:12
  • This is exactly what we are missing to make minimal debugging and try help you Commented Jan 11, 2023 at 10:14
  • Can you add HTML source for that element you want to click Commented Jan 11, 2023 at 12:22
  • TimeoutException meaning one of the 3 web elements you trying to locate fail and hit timeout error. You need to provide more details such as the URL or site that you are trying to access. Or at least some sample HTML source to determine if your locator is working properly. Commented Jan 11, 2023 at 14:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.