0

I face the following issue: there is a page (unfortunately it's not public) with a Register request and a Approve request button. Clicking on a button leads to opening a transparent div with a pop-up.

Algorithm is as following: 1) Click Register; 2) Fill form in raised pop-up; 3) Click Submit to confirm registration (to close pop-up); 4) Click Approve

So I use the following code:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[@id="RegisterButton"]'))).click()
# ...Filling Register form...
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[@id="SubmitButton"]'))).click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//button[@id="ApproveButton"]'))).click()

But despite using EC.element_to_be_clickable() I get the following error:

 WebDriverException: Message: unknown error: 
 Element is not clickable at point (338, 167). 
 Other element would receive the click: <div class="modal fade" id="confirmWindow" style="display: block;">...</div>

Seems that the driver considers Approve being already clickable and tries to click on it while the transparent div is still displayed.

So I need an Expected Conditions statement to catch the state when the div is already selected and Approve if the button is clickable

P.S. I'm using time.sleep() to do this, but seems to be a rough approach

UPDATED

I try to use JavaScript:

driver.execute_script('document.getElementById("ApproveButton").click();')

and so far it works... I wonder if it really a better way to click on button or there could be some obstacles also?

Andersson
  • 51,635
  • 17
  • 77
  • 129
  • Hi @ andersson your code is working properly as it is confirmed form the error that you are getting "Element is not clickable at point (338, 167). " and also Thread.sleep is working because the element for which you have applied EC is present in the DOM but yet it has not fixed position in the DOM and this error generally occurs in Google Chrome browser i can bet you are on chrome – Rajnish Kumar May 27 '16 at 09:18
  • to overcome this issue plz have a look at this link http://stackoverflow.com/questions/37388866/selenium-element-is-not-clickable-at-point/37389577#37389577 – Rajnish Kumar May 27 '16 at 09:24
  • Yeap, I use `Chromedriver`. Thanks for link, I'll check it – Andersson May 27 '16 at 09:47
  • yeah sure a quick solution is simply change the browser it will work for sure thanks – Rajnish Kumar May 27 '16 at 09:48
  • What happens if you increase the timeout on the webdriverwait of the approve button? – RemcoW May 27 '16 at 13:31
  • 1
    @RemcoW, timeOut increasing makes no effect – Andersson May 27 '16 at 14:15

1 Answers1

3

Understandably using a time.sleep() is something you want to avoid. Since it clicks on the modal I am assuming the button is considered clickable even though the modal isn't fully disappeared yet. In this case I would add another wait that waits till the modal is no longer visible.

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@id="RegisterButton"]'))).click()
# ...Filling Register form...
wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@id="SubmitButton"]'))).click()

# Wait till the modal is no longer visible
wait.until_not(EC.visibility_of_element_located((By.ID, 'confirmWindow')))

wait.until(EC.element_to_be_clickable((By.XPATH, '//button[@id="ApproveButton"]'))).click()

Note: I've also created a single instance of WebDriverWait instead of making a new one for each wait like you did in your example. There is no need to create a new instance all the time.

RemcoW
  • 4,196
  • 1
  • 22
  • 37