[Python] Unable to import selenium.webdriver.common.by

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    While trying to run selenium commands in Python, I am not able to import selenium.webdriver.common.by. However, the library 'selenium' is finely imported. I am running the program in VS Code.

    Script:-

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    driver = webdriver.Chrome()

    driver.get("https://**.com")
    search_id = "123"
    search_elem = driver.find_element(By.ID, search_id)
    #search_elem.send_keys("**email.com")

    breakpoint()


    Error:-

    PS C:\Users\Desktop\python selenium> python test.py

    DevTools listening on ws://***/devtools/browser/44ebdc50-e0c6-43e6-a329-85c2e96b0892
    Traceback (most recent call last):
    File "C:\Users\Desktop\python selenium\test.py", line 7, in <module>
    search_elem = driver.find_element(By.ID, search_id)
    File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 748, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
    File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 354, in execute
    self.error_handler.check_response(response)
    File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="i0116"]"}
    (Session info: chrome=128.0.6613.138); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception


    [​IMG]

    Continue reading...

Compartilhe esta Página