Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.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
如何使用Selenium和python在浏览器的第二个窗口上单击按钮_Python_Selenium - Fatal编程技术网

如何使用Selenium和python在浏览器的第二个窗口上单击按钮

如何使用Selenium和python在浏览器的第二个窗口上单击按钮,python,selenium,Python,Selenium,我正在从事一个项目,其中代理使用python和selenium进行购物,现在当我单击google plus按钮时,如图所示,google plus按钮工作正常,但当我尝试使用selenium在第二个窗口中单击帐户(daigram中的2个数字)时,会出现以下错误,即使我尝试使用不同的选择器: 代码: account=driver.find_element_by_class_name('w1I7fb') account.click() 错误: selenium.common.exceptions.

我正在从事一个项目,其中代理使用python和selenium进行购物,现在当我单击google plus按钮时,如图所示,google plus按钮工作正常,但当我尝试使用selenium在第二个窗口中单击帐户(daigram中的2个数字)时,会出现以下错误,即使我尝试使用不同的选择器:

代码:

account=driver.find_element_by_class_name('w1I7fb')
account.click()
错误:

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{“方法”:“css选择器”,“选择器”:.w1I7fb”}


单击Google Plus按钮,新窗口将打开。
您必须将驱动程序切换到新窗口。
所以在点击Google Plus按钮之后

new_window = driver.window_handles[1]
driver.switch_to_window(new_window)

现在,在新窗口中,您应该通过以下
xpath
//div[@data identifier='your]找到一个元素_email@gmail.com“]
然后单击它

当然,我的打字错误。很抱歉如果它解决了问题,请接受答案X,它工作得很好。如果是,请接受我的回答。