I am running python 3.9 with the following code. When I run the script I get the error message. Not sure what I am missing. The element is called username.
File "/Users/user/Documents/PycharmProjects/webscrapping/app/webscraping.py", line 19, in <module>
login = driver.find_element("username") File "/Users/user/Documents/VENV/webscrapping/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 1244, in find_element
return self.execute(Command.FIND_ELEMENT, { File "/Users/user/Documents/VENV/webscrapping/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 424, in execute
self.error_handler.check_response(response)
File "/Users/user/Documents/VENV/webscrapping/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator (Session info: chrome=98.0.4758.80) Stacktrace: 0 chromedriver 0x0000000102a5c3c9 chromedriver + 5018569 1 chromedriver 0x00000001029e7333 chromedriver + 4539187 2 chromedriver 0x00000001025bca88 chromedriver + 170632 3 chromedriver 0x00000001025f0d81 chromedriver + 384385 4 chromedriver 0x00000001025f14f1 chromedriver + 386289 5 chromedriver 0x00000001026238b4 chromedriver + 592052 6 chromedriver 0x000000010260e80d chromedriver + 505869 7 chromedriver 0x0000000102621604 chromedriver + 583172 8 chromedriver 0x000000010260e6d3 chromedriver + 505555 9 chromedriver 0x00000001025e495e chromedriver + 334174 10 chromedriver 0x00000001025e5935 chromedriver + 338229 11 chromedriver 0x0000000102a181ee chromedriver + 4739566 12 chromedriver 0x0000000102a31f51 chromedriver + 4845393 13 chromedriver 0x0000000102a37928 chromedriver + 4868392 14 chromedriver 0x0000000102a32a7a chromedriver + 4848250 15 chromedriver 0x0000000102a0cc31 chromedriver + 4693041 16 chromedriver 0x0000000102a4d978 chromedriver + 4958584 17 chromedriver 0x0000000102a4db01 chromedriver + 4958977 18 chromedriver 0x0000000102a63795 chromedriver + 5048213 19 libsystem_pthread.dylib 0x00007ff80f7a24f4 _pthread_start + 125 20 libsystem_pthread.dylib 0x00007ff80f79e00f thread_start + 15
Code trials:
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
CURRENT_DIR = os.getcwd()
print(f"Current Dir is {CURRENT_DIR}")
driver = webdriver.Chrome(f"{CURRENT_DIR}/chromedriver")
url = 'https://somewebsite.com/login2/'
driver.get(url)
time.sleep(2)
login = driver.find_element('username')
login.send_keys('[email protected]')
login.send_keys(Keys.RETURN)
time.sleep(5)
driver.quit()
HTML im trying to get:
<div class="sc-dnqmqq jomEGJ" data-reactid=".0.1.0.2.1.0.0.0">
<label class="sc-iwsKbI hOobUj" for="username" data-reactid=".0.1.0.2.1.0.0.0.0">
<span data-reactid=".0.1.0.2.1.0.0.0.0.0">Username</span>
</label>
</div>
find_element('username')
That function requires two arguments, but you're only providing one. – Dictate