Reputation: 89
Can you help me with my code? I want to parse phone numbers, but I need to activate button with tap. But this button is with a tag and this is a problem for me. How can I fix it?
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()
Error:
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
Upvotes: 2
Views: 1674
Reputation: 193098
This error message...
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
...implies that there an error with the subprocess.Popen()
command.
As per the discussion in Selenium 3.5.0-GeckoDriver 0.18.0-Python 3.6.1 : "OSError: [WinError 6] The handle is invalid" is observed while close() is called through Python PyDev (Eclipse) unittest module this issue was observed even while invoking self.driver.close()
through Python's unittest module.
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)
The solution was merged from the Also define stdin or it will crash on Python + cx_Freeze: WindowsErro… pull request and was available in Selenium v3.8.1
Ideally, you need toensure that:
driver.quit()
within tearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.subprocess.Popen._cleanup() "The handle is invalid" error when some old process is gone
Upvotes: 1
Reputation: 748
Your code looks fine... Your environment looks suspect. If I were to hazard a guess (since it's the subprocess module complaining), maybe Selenium can't find chrome.exe in your PATH. Does Chrome open before this exception?
Upvotes: 0