Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 单击按钮后使用Selenium切换到新窗口_Python_Xml_Selenium - Fatal编程技术网

Python 单击按钮后使用Selenium切换到新窗口

Python 单击按钮后使用Selenium切换到新窗口,python,xml,selenium,Python,Xml,Selenium,我正在做一个相当简单的网页项目,有点卡住了。我正在使用一个网站,在填写表单并单击按钮后,该网站将在新窗口中打开XML文档时提供所需的数据。但是,我不知道如何访问它,因为我没有得到窗口名 browser = Browser('firefox') browser.visit('http://desiredurl/') form = browser.find_by_id('input') button = browser.find_by_id('send') form.fill(string) but

我正在做一个相当简单的网页项目,有点卡住了。我正在使用一个网站,在填写表单并单击按钮后,该网站将在新窗口中打开XML文档时提供所需的数据。但是,我不知道如何访问它,因为我没有得到窗口名

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

单击按钮触发ajax请求(doAjaxRequest(“POST”,url,xml);)并打开一个包含xml文档的新窗口。从打开的XML中访问数据的最佳方法是什么?

您的问题的解决方案将是使用
预期的\u条件将
诱导为
窗口数\u to \u be
,然后切换到新窗口,如下所示:

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)) 

为初学者提供一点帮助:来自selenium.webdriver.support将预期的_条件导入为EC