Home > Enterprise >  Python - Contents not printing from Selenium
Python - Contents not printing from Selenium

Time:06-28

Noob coder here trying to learn Selenium. I was following a Youtube tutorial by this channel and I have this code which doesn't work for me but works fine when he runs it in the tutorial. Can you please tell me if I have made some mistake? Here is the code.

from selenium import webdriver

from selenium.webdriver.chrome.service import Service

from selenium.webdriver.common.by import By

from selenium.webdriver.common.keys import Keys

serv_obj = Service("C:\chromedriver.exe")

driver = webdriver.Chrome(service=serv_obj)

driver.get("https://techwithtim.net")

print(driver.title)

search = driver.find_element(By.NAME, "s")

search.send_keys("test")

search.send_keys(Keys.RETURN)

try: main = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "main")))

print(main.text)

except:

driver.quit()

And this is the error that I get.

Traceback (most recent call last): File "C:\Users\DaTenshi\PycharmProjects\Scraping\new_scrape.py", line 14, in search.send_keys(Keys.RETURN)

File "C:\Users\DaTenshi\PycharmProjects\Scraping\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 223, in send_keys self._execute(Command.SEND_KEYS_TO_ELEMENT,

File "C:\Users\DaTenshi\PycharmProjects\Scraping\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 396, in _execute return self._parent.execute(command, params)

File "C:\Users\DaTenshi\PycharmProjects\Scraping\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute self.error_handler.check_response(response)

File "C:\Users\DaTenshi\PycharmProjects\Scraping\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status from unknown error: unexpected command response

(Session info: chrome=103.0.5060.53)

Stacktrace:

Backtrace: Ordinal0 [0x00E26463 2188387]

Ordinal0 [0x00DBE461 1762401]

Ordinal0 [0x00CD3D78 802168]

Ordinal0 [0x00CC7210 750096]
Ordinal0 [0x00CC675A 747354]
Ordinal0 [0x00CC5D3F 744767]
Ordinal0 [0x00CC4C28 740392]
Ordinal0 [0x00CC5228 741928]
Ordinal0 [0x00CCEF2F 782127]
Ordinal0 [0x00CD9FBB 827323]
Ordinal0 [0x00CDD310 840464]
Ordinal0 [0x00CC54F6 742646]
Ordinal0 [0x00CD9BF3 826355]
Ordinal0 [0x00D2CF6D 1167213]
Ordinal0 [0x00D1C5F6 1099254]
Ordinal0 [0x00CF6BE0 945120]
Ordinal0 [0x00CF7AD6 948950]
GetHandleVerifier [0x010C71F2 2712546]
GetHandleVerifier [0x010B886D 2652765]
GetHandleVerifier [0x00EB002A 520730]
GetHandleVerifier [0x00EAEE06 516086]
Ordinal0 [0x00DC468B 1787531]
Ordinal0 [0x00DC8E88 1805960]
Ordinal0 [0x00DC8F75 1806197]
Ordinal0 [0x00DD1DF1 1842673]
BaseThreadInitThunk [0x76696A14 36]
RtlInitializeExceptionChain [0x774AA9FF 143]
RtlInitializeExceptionChain [0x774AA9CA 90]

CodePudding user response:

Change these lines of code:

serv_obj = Service("C:\chromedriver.exe")
driver = webdriver.Chrome(service=serv_obj)

So here and import these modules:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager

servico = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=servico)

CodePudding user response:

I believe this is an active bug that was introduced with the Chrome 103. You can track them below -

https://groups.google.com/g/chromedriver-users/c/BroyfA_GXNQ

https://bugs.chromium.org/p/chromedriver/issues/detail?id=4121

  • Related