Home > Software design >  InvalidArgumentException Error when running selenium
InvalidArgumentException Error when running selenium

Time:12-22

Very new to coding and started learning selenium. Below is the code I ran which opened the browser but the moment I try to find an element within the page, I get this InvalidArgumentException error with a bunch of backtrace information. I can not post images yet since I am new so I can not show exactly what the error looks like.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys # gives access to keys like enter
import time

path = r"C:\...\chromedriver.exe"
driver = webdriver.Chrome(path)

driver.get('https://www.yahoo.com')

search = driver.find_element("_yb_nuzqf")
search.send_keys("test")
search.send_keys(Keys.RETURN)

time.sleep(5)

driver.quit()

This is the errors output:

Exception has occurred: InvalidArgumentException
Message: invalid argument: invalid locator
  (Session info: chrome=108.0.5359.125)
Stacktrace:
Backtrace:
    (No symbol) [0x00A3F243]
    (No symbol) [0x009C7FD1]
    (No symbol) [0x008BD04D]
    (No symbol) [0x008EC1BE]
    (No symbol) [0x008EC22B]
    (No symbol) [0x0091E612]
    (No symbol) [0x009085D4]
    (No symbol) [0x0091C9EB]
    (No symbol) [0x00908386]
    (No symbol) [0x008E163C]
    (No symbol) [0x008E269D]
    GetHandleVerifier [0x00CD9A22 2655074]
    GetHandleVerifier [0x00CCCA24 2601828]
    GetHandleVerifier [0x00AE8C0A 619850]
    GetHandleVerifier [0x00AE7830 614768]
    (No symbol) [0x009D05FC]
    (No symbol) [0x009D5968]
    (No symbol) [0x009D5A55]
    (No symbol) [0x009E051B]
    BaseThreadInitThunk [0x77617D69 25]
    RtlInitializeExceptionChain [0x77C5BB9B 107]
    RtlClearBits [0x77C5BB1F 191]

I tried looking up what the error was or if anyone else had this issue. I can not seem to locate how to solve this problem

CodePudding user response:

driver.find_element("_yb_nuzqf") line is wrong.
find_element method receives a By object which is a pair of "what you locating the element by" and the actual value. For example it could be

driver.find_element(By.ID, "_yb_nuzqf")

or

driver.find_element(By.CLASS_NAME, "_yb_nuzqf")

To use it you need to import this:

from selenium.webdriver.common.by import By

CodePudding user response:

Use the locater to find elements.

EX >> driver.find_element(By.ID,"_yb_nuzqf")

  • Related