T
T
TempUserForToster2014-02-19 20:03:09
Software testing
TempUserForToster, 2014-02-19 20:03:09

How to implement popup element access using Selenium?

The site page has a form and a button.
After filling out the form and clicking on the button, a pop-up window appears with another button. This updates the DOM to include the popup code.
Can you please tell me how to click on a button in a pop-up window using Selenium?
Looking ahead, tried (Python code):
1)

WebDriverWait(driver, 10);
driver.find_element_by_xpath("//div[@id='nameId']/div/div[2]").click();

Throws an error:
selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate 
element: {"method":"xpath","selector":"//div[@id=\'nameId\']/div/div[2]"}'

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

But it creates an error:
selenium.common.exceptions.NoSuchElementException: Message: 'Unable to locate 
element: {"method":"xpath","selector":"//div[@id=\'nameId\']/div/div[2]"}' ;

If the code is replaced with:
driver.switch_to_alert();
driver.find_elements_by_xpath("//div[@id='nameId']/div/div[2]").click()

then an error appears:
AttributeError: 'list' object has no attribute 'click'
UPD:
Issue resolved.
The popup turned out to be just a new element in the HTML tag of the original page.
To access the element of the window that appears, you must execute (XPath changed to the correct one):
time.sleep(10)
driver.find_element_by_xpath("//div[@class='nameId']/div[@sbisname='Ok']/div").click();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Rotaty, 2014-02-19
@Flamine

Hello. You need a switch_to_popup method, maybe switch_to_popup_window.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question