Click on a button within a pop-up window with python selenium

0 votes

The GUI as below: GUI. HTML content as below: HTML. I'm trying to use python selenium to click the "OK" button in many ways: For example:

driver.switch_to_alert()
driver.find_element_by_id("YesBtn").click()

or

driver.switch_to_alert()
driver.find_element_by_xpath("//div[@id='YesBtn']").click()

or

driver.switch_to_alert()
driver.find_element_by_xpath("//input[@id='YesBtn']/html/body/div/div/div/div/div[3]").click()

But I always get error message like:

Unable to locate element: {"method":"id","selector":"YesBtn"}

Please help in this matter

Jun 20, 2018 in Selenium by Martin
• 4,220 points
5,915 views

1 answer to this question.

0 votes

It's not an Alert but a Modal Dialog Box. You have to induce WebDriverWait in-conjunction with expected_conditions clause set to element_to_be_clickable as follows :

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='btn btn-primary' and @id='YesBtn']"))).click()

answered Jun 20, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

0 votes
1 answer

Python & Selenium: How to find and click on YouTube's Like button

Use the CSS Selector button to like: #watch8-sentiment-actions ...READ MORE

answered Mar 26, 2018 in Selenium by nsv999
• 5,050 points
531 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
402 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
757 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
400 views
0 votes
1 answer

Angular JS: Selenium cannot click a button by python code on mac

You can try clicking it with javascript ...READ MORE

answered Aug 9, 2018 in Selenium by Samarpit
• 5,130 points
681 views
0 votes
1 answer

How to click a span with given text using Selenium Python

If ALL_USA is subject to change, then ...READ MORE

answered Jul 26, 2018 in Selenium by Samarpit
• 5,130 points
1,640 views