Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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打开新选项卡的链接时,无法关注firefox中的新选项卡_Python_Selenium_Geckodriver - Fatal编程技术网

单击使用selenium和python打开新选项卡的链接时,无法关注firefox中的新选项卡

单击使用selenium和python打开新选项卡的链接时,无法关注firefox中的新选项卡,python,selenium,geckodriver,Python,Selenium,Geckodriver,提到的xpath是链接的xpath。在执行driver.execute_脚本后的上述代码中,链接在新选项卡中打开,但driver.title仍显示旧选项卡的标题,因此无法识别新选项卡中的新元素。有人能帮我吗 使用的Selenium版本:3.11.0 使用的Firefox版本:47.0.2 使用的geckodriver版本:0.14如果单击“下一步”按钮后,页面在新选项卡中打开,则必须将WebDriver的焦点切换到该窗口 element=driver.find_element_by_xpath(

提到的xpath是链接的xpath。在执行driver.execute_脚本后的上述代码中,链接在新选项卡中打开,但driver.title仍显示旧选项卡的标题,因此无法识别新选项卡中的新元素。有人能帮我吗

使用的Selenium版本:3.11.0 使用的Firefox版本:47.0.2
使用的geckodriver版本:0.14

如果单击“下一步”按钮后,页面在新选项卡中打开,则必须将WebDriver的焦点切换到该窗口

element=driver.find_element_by_xpath("html/body/footer/div/div[1]/section/div/div/div[2]/div[1]/ul/li[9]/div/div/a")
driver.execute_script("arguments[0].click();", element)
print(driver.title)

尝试了您的建议,但出现错误tabs=driver.getWindow\u Handles AttributeError:“WebDriver”对象没有属性“getWindow\u Handles”不,它不起作用。问题是我共享的代码在Chrome上运行得很好,但在Firefox上却不行。在Chrome中,它可以切换到新的选项卡,但在Firefox中它失败了。elm=driver。通过xpath(“html/body/footer/div/div/div[1]/section/div/div/div[2]/div[1]/ul/li[9]/div/div/div/a”)驱动程序查找元素。执行脚本(“参数[0]。单击()”,elm)驱动程序。切换到窗口(驱动程序。窗口处理[1])打印(驱动程序。当前url)我尝试了上面的代码和驱动程序。当前的_url返回“about:blank”,因为“html/body/footer/div/div[1]/section/div/div[2]/div[1]/ul/li[9]/div/div/a此Xpath有一些严重问题。可能重复
window_before = driver.window_handles[0]
# Click on next button on Page 1.
# Opens a new tab
window_after = driver.window_handles[1]
driver.switch_to_window(window_after)

#performs some operations on Page 2.
print(driver.title)
driver.close()

driver.switch_to.window(window_before )