Home > Software design >  selenium find elements don't work it doesn't find elements nad send keys
selenium find elements don't work it doesn't find elements nad send keys

Time:07-31

it can find the elements at the site and i am sure from method name and every step i make with selenium i got error can i solve this error at once with any replacement
this is the code

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
options = Options()
options.add_experimental_option("detach", True)
d = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
d.get('https://elzero.org/')
d.find_element(By.CLASS_NAME, "form").send_keys('python')

and this the Traceback:

Traceback (most recent call last):
  File "C:\Users\abdal\PycharmProjects\pythonProject\main.py", line 11, in <module>
    d.find_element(By.NAME, "form").send_keys('python')
  File "C:\Users\abdal\PycharmProjects\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 857, in find_element
    return self.execute(Command.FIND_ELEMENT, {
  File "C:\Users\abdal\PycharmProjects\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute
    self.error_handler.check_response(response)
  File "C:\Users\abdal\PycharmProjects\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, 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":"[name="form"]"}
  (Session info: chrome=103.0.5060.134)
Stacktrace:
Backtrace:
    Ordinal0 [0x011B5FD3 2187219]
    Ordinal0 [0x0114E6D1 1763025]
    Ordinal0 [0x01063E78 802424]
    Ordinal0 [0x01091C10 990224]
    Ordinal0 [0x01091EAB 990891]
    Ordinal0 [0x010BEC92 1174674]
    Ordinal0 [0x010ACBD4 1100756]
    Ordinal0 [0x010BCFC2 1167298]
    Ordinal0 [0x010AC9A6 1100198]
    Ordinal0 [0x01086F80 946048]
    Ordinal0 [0x01087E76 949878]
    GetHandleVerifier [0x014590C2 2721218]
    GetHandleVerifier [0x0144AAF0 2662384]
    GetHandleVerifier [0x0124137A 526458]
    GetHandleVerifier [0x01240416 522518]
    Ordinal0 [0x01154EAB 1789611]
    Ordinal0 [0x011597A8 1808296]
    Ordinal0 [0x01159895 1808533]
    Ordinal0 [0x011626C1 1844929]
    BaseThreadInitThunk [0x752AFA29 25]
    RtlGetAppContainerNamedObjectPath [0x77207A9E 286]
    RtlGetAppContainerNamedObjectPath [0x77207A6E 238]

CodePudding user response:

There is no such element with class form in your page. Also you can send keys only to a input element and not a form element.

This should work

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium import webdriver


options = Options()

options.add_experimental_option("detach", True)
d = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

d.get('https://elzero.org/')
d.find_element(By.ID, "search").send_keys('python')

Additionaly you can send ENTER key to search the token.

d.find_element(By.ID, "search").send_keys(Keys.ENTER)
  • Related