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
在python selenium中切换窗口时出错_Python_Selenium_Selenium Webdriver - Fatal编程技术网

在python selenium中切换窗口时出错

在python selenium中切换窗口时出错,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我想使用selenium和python处理多个窗口和选项卡 我在脚本执行期间遇到以下错误:- (最后提到代码) 您将收到一条警告消息,对于新版本的selenium,该方法已更改 不要使用:driver。切换到窗口(window) 尝试:驱动程序。切换到.window 其中窗口是您的变量。如警告所示 弃用警告:改用driver.switch\u to.window 你需要换一下衣服 driver.switch_to_window 与 但想想看:这是一个警告,而不是一个错误!您的代码应该可以工作

我想使用selenium和python处理多个窗口和选项卡

我在脚本执行期间遇到以下错误:- (最后提到代码)



您将收到一条警告消息,对于新版本的selenium,该方法已更改

不要使用:
driver。切换到窗口(window)

尝试:
驱动程序。切换到.window

其中
窗口
是您的变量。

如警告所示

弃用警告:改用driver.switch\u to.window

你需要换一下衣服

driver.switch_to_window


但想想看:这是一个警告,而不是一个错误!您的代码应该可以工作,它只是告诉您该方法已被弃用。

我建议使用一种非常简单的方法在窗口之间切换,而无需亲自玩手柄


这是错误还是警告?
import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

class GoogleTabs(unittest.TestCase):

 def setUp(self):
     self.driver = webdriver.Firefox()

 def test_google_search_page(self):
     driver = self.driver
     driver.get("http://www.cdot.in")
     window_before = driver.window_handles[0]
     print (window_before)
     driver.find_element_by_xpath("//a[@href='http://www.cdot.in/home.htm']").click()
     window_after = driver.window_handles[1]
     driver.switch_to_window(window_after)
     print (window_after)
     driver.find_element_by_link_text("ATM").click()
     driver.switch_to_window(window_before)


 def tearDown(self):
     self.driver.close()

if __name__ == "__main__":
unittest.main()
driver.switch_to_window
driver.switch_to.window
def change_window(browser):
    """
    Simple window switcher without the need of playing with ids.
    @param browser: Current browser instance
    """
    curr = browser.current_window_handle
    all_handles = browser.window_handles
    for handle in list(set([curr]) - set(all_handles)):
        return browser.switch_to_window(handle)