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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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_Selenium Webdriver_Subprocess_Eoserror_Unittest - Fatal编程技术网

OSError:[WinError 6]通过Python使用Selenium时出现错误的描述符错误

OSError:[WinError 6]通过Python使用Selenium时出现错误的描述符错误,python,selenium,selenium-webdriver,subprocess,eoserror,unittest,Python,Selenium,Selenium Webdriver,Subprocess,Eoserror,Unittest,你能帮我写代码吗?我想解析电话号码,但我需要通过点击激活按钮。但是这个按钮有标签,这对我来说是个问题。我怎样才能修好它 from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains #from selenium.webdriver.common.touch_actions

你能帮我写代码吗?我想解析电话号码,但我需要通过点击激活按钮。但是这个按钮有标签,这对我来说是个问题。我怎样才能修好它

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
#from selenium.webdriver.common.touch_actions import TouchActions
#import org.openqa.selenium.interactions.Actions


#TouchActions.tap
def main():
    driver = webdriver.Chrome()
    remote = driver.get("https://www.olx.ua/uk/obyavlenie/68200jk71a-torpedo-pod-airbag-infiniti-g-07-14-infiniti-IDGRpUS.html#d97e6d976d;promoted")
    bt_elem = driver.find_elements_by_id("postNewAdLink")
    #print(bt_elem[0])
    #driver.find_elements_by_class_name("contact-button").click()
    #ActionChains(driver).move_to_element(bt_elem).perform().click()

    #bt_elem.get(0).click()
    #TouchActions.tap(bt_elem)

main()
错误:

Traceback (most recent call last):
  File "C:\Users\radus\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 945, in __del__
    self._internal_poll(_deadstate=_maxsize)
  File "C:\Users\radus\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1344, in _internal_poll
    if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] Wrong descriptor

你的代码看起来很好。。。您的环境看起来可疑。如果我冒昧猜测一下(因为是子流程模块在抱怨),可能Selenium在您的路径中找不到chrome.exe。Chrome是否在此异常之前打开?

此错误消息

  File "C:\Users\radus\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 945, in __del__
    self._internal_poll(_deadstate=_maxsize)
  File "C:\Users\radus\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1344, in _internal_poll
    if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:
OSError: [WinError 6] Wrong descriptor
…表示
subprocess.Popen()命令出现错误


根据本期的讨论,即使在通过Python模块调用
self.driver.close()
时也观察到了这种情况


解决方案 该解决方案已从拉取请求中合并,并可在
Selenium v3.8.1

理想情况下,您需要确保:

  • 硒被提升到当前水平
  • ChromeDriver已更新到当前级别
  • Chrome更新至当前Chrome版本80.0级别。(根据)
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • 始终在
    tearDown(){}
    方法中调用
    driver.quit()
    ,以优雅地关闭和销毁Web驱动程序和Web客户端实例

tl;博士

看看这里@Vladimir很高兴能帮助您。如果这个/任何答案对你有帮助,对未来的读者有好处。
This is because there is no stdin defined in the `service.py` file for the `subprocess.Popen()` command. Underwater the subprocess tries to create a handle which also looks for stdin under Windows this gets a bit tricky when using `Bash` or `cx_Freeze`. So, `stdin` was defined as well, and the crash is gone. Optionally you can also use:

FNULL = open(os.devnull, 'r')
subprocess.Popen(.... ,stdin=FNULL)