Search code examples
pythonselenium-webdriverweb-scrapingselenium-chromedriverwebdriver

Python Selenium Scraping error when scrape custom element


I am trying to scrape custom element, but i can not. My code worked perfectly for previous versions of Selenium and Chrome, but after update it stop working. I can get full page HTML, but i can not reach custom element i want.Here is e code:

from selenium import webdriver
from selenium.webdriver.common.by import By


driver = webdriver.Chrome()
driver.get('https://w8shippingge.com/customer-zone/')


driver.find_element(By.NAME,'login').send_keys("password")

I get error:

DevTools listening on ws://127.0.0.1:51742/devtools/browser/eb5109e6-3d4f-4460-bf38-e94f621d2443
Traceback (most recent call last):
  File "c:/Users/Admin/Desktop/for test.py", line 9, in <module>
    driver.find_element(By.NAME,'login').send_keys("password")
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 855, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in execute
    self.error_handler.check_response(response)
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Runtime.callFunctionOn threw exception: TypeError: JSON.stringify is not a function
    at buildError (<anonymous>:323:18)
  (Session info: chrome=113.0.5672.127)
Stacktrace:
Backtrace:
        GetHandleVerifier [0x00338893+48451]
        (No symbol) [0x002CB8A1]
        (No symbol) [0x001D5058]
        (No symbol) [0x001D8176]
        (No symbol) [0x001D9631]
        (No symbol) [0x001D96D0]
        (No symbol) [0x002000C0]
        (No symbol) [0x0020069B]
        (No symbol) [0x0022DD92]
        (No symbol) [0x0021A304]
        (No symbol) [0x0022C482]
        (No symbol) [0x0021A0B6]
        (No symbol) [0x001F7E08]
        (No symbol) [0x001F8F2D]
        GetHandleVerifier [0x00598E3A+2540266]
        GetHandleVerifier [0x005D8959+2801161]
        GetHandleVerifier [0x005D295C+2776588]
        GetHandleVerifier [0x003C2280+612144]
        (No symbol) [0x002D4F6C]
        (No symbol) [0x002D11D8]
        (No symbol) [0x002D12BB]
        (No symbol) [0x002C4857]
        BaseThreadInitThunk [0x76000419+25]
        RtlGetAppContainerNamedObjectPath [0x77C3662D+237]
        RtlGetAppContainerNamedObjectPath [0x77C365FD+189]

i tried to add time.sleep() but no result, i get same error.


Solution

  • If you are not specific about using Chrome, try using Firefox. It should work.

    Change this:

    driver = webdriver.Chrome()
    

    To:

    driver = webdriver.Firefox()
    

    At this stage, am not too sure about the root cause of the issue in Chrome though.