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
如何修复OSError:[WinError 6]该句柄在Python和Selenium中无效?_Python_Selenium_Xpath_Css Selectors_Webdriverwait - Fatal编程技术网

如何修复OSError:[WinError 6]该句柄在Python和Selenium中无效?

如何修复OSError:[WinError 6]该句柄在Python和Selenium中无效?,python,selenium,xpath,css-selectors,webdriverwait,Python,Selenium,Xpath,Css Selectors,Webdriverwait,我正在尝试使用Selenium和Fidelity登录我的Fidelity帐户。我已经确保使用了正确的网络驱动程序(Chrome版本78的版本78)。我认为这与Chrome webdriver只有32位有关,而我使用的是64位。这是我遇到的最后一个错误。它打开网页,输入我的用户名和密码,然后我想点击按钮,它就会崩溃或者就在它之前 从selenium导入webdriver def测试机器人(用户名、密码): chrome\u options=webdriver.ChromeOptions() chr

我正在尝试使用Selenium和Fidelity登录我的Fidelity帐户。我已经确保使用了正确的网络驱动程序(Chrome版本78的版本78)。我认为这与Chrome webdriver只有32位有关,而我使用的是64位。这是我遇到的最后一个错误。它打开网页,输入我的用户名和密码,然后我想点击按钮,它就会崩溃或者就在它之前

从selenium导入webdriver
def测试机器人(用户名、密码):
chrome\u options=webdriver.ChromeOptions()
chrome_选项。添加_实验性_选项(“ExcludeSwitchs”,['enable-automation'])
br=webdriver.Chrome(Chrome\u选项=Chrome\u选项)
br.get(“https://www.fidelity.com")
br.隐式等待(10)
user=br.通过\u id('userId-input')查找\u元素
user.clear()
用户。发送密钥(用户名)
pwd=br.通过\u id(“密码”)查找\u元素\u
pwd.clear()
pwd.发送密钥(密码)
btn=br.通过\u id('fs-login-button')查找\u元素
点击()
测试机器人(“我的用户名”、“我的密码”)
这是我得到的错误

Exception ignored in: <function Popen.__del__ at 0x03957270>
Traceback (most recent call last):
  File "C:\Users\Notebook\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 860, in __del__
    self._internal_poll(_deadstate=_maxsize)
  File "C:\Users\Notebook\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1216, in _internal_poll
    if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] The handle is invalid
中忽略的异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\Notebook\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py”,第860行,在__
self.\u internal\u poll(\u deadstate=\u maxsize)
文件“C:\Users\Notebook\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py”,第1216行,在内部轮询中
如果WaitForSingleObject(self.\u handle,0)=\u WAIT\u OBJECT\u 0:
OSError:[WinError 6]句柄无效
我正在使用Pycharm和Selenium。

要将字符序列发送到UsenamePassword字段,您必须诱导WebDriverWait使
元素可点击()
,并且您可以使用以下任一选项:

  • 使用
    CSS\u选择器

    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")
    #options.add_experimental_option("excludeSwitches", ["enable-automation"])
    #options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://www.fidelity.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#userId-input"))).send_keys("Brandon")
    driver.find_element_by_css_selector("input#password").send_keys("Jacobson")
    driver.find_element_by_css_selector("button#fs-login-button").click()
    
  • 使用
    XPATH

    options = webdriver.ChromeOptions()
    options.add_argument("start-maximized")
    #options.add_experimental_option("excludeSwitches", ["enable-automation"])
    #options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
    driver.get("https://www.fidelity.com/")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='userId-input']"))).send_keys("Brandon")
    driver.find_element_by_xpath("//input[@id='password']").send_keys("Jacobson")
    driver.find_element_by_xpath("//button[@id='fs-login-button']").click()
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

您是否尝试过对
chrome\u选项进行评论。添加\u实验性选项(“ExcludeSwitchs”、['enable-automation'])
line?谢谢您的推荐。我试着把它评论出来,但仍然不起作用。这条线防止Chrome因为你使用自动化而对你大喊大叫。你的CSS_选择器工作了!非常感谢。我不得不将options=改为:driver=webdriver.Chrome(Chrome\u options=options)