2

I'm working on quite a simple webpage project and got stuck a bit. I'm using a website that after filling the form and clicking the button gives me my desired data in for of XML document opening in a new window. However, I have no clue how to access it, as I am not given the window name

browser = Browser('firefox')
browser.visit('http://desiredurl/')
form = browser.find_by_id('input')
button = browser.find_by_id('send')
form.fill(string)
button.click()

Clicking on a button triggers an ajax request (doAjaxRequest("POST", url, xml);) and opens a new window with XML document. What is the best way to access data from opened XML?

0

1 Answer 1

2

The solution for your question will be to induce Explicitwait with expected_conditions as number_of_windows_to_be and then switch over to the new window as follows :

parent = driver.current_window_handle
button = browser.find_by_id('send')
form.fill(string)
button.click()
WebDriverWait(driver, 10).until(
    EC.number_of_windows_to_be(2)
    )   
child = driver.window_handles[1]      
driver.switch_to_window(child) 
print ("Child Window ID is : %s" %child)
print("Child Window Title is : %s " %(driver.title)) 

You have to add the following imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

1 Comment

For beginners a little help: from selenium.webdriver.support import expected_conditions as EC

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.