I am essentially scraping chegg and I need help in trying to identify the css id= "emailForSignIn" I am trying to find a way to detect where the text bar for the login section is for the chegg login page
Below is the function implemented:
def signin(): # Only use this function if you are using new instances of your browser each time
print('>>signing in!')
browser.get('https://www.chegg.com/auth?action=login&redirect=https%3A%2F%2Fwww.chegg.com%2F')
handle_captcha()
time.sleep(2)
email_elem = browser.find_element_by_id('emailForSignIn')
for character in 'alondra_calderon@ymail.com':
email_elem.send_keys(character)
time.sleep(0.1)
time.sleep(2)
password_elem = browser.find_element_by_id('passwordForSignIn')
for character in 'Blueyes97':
password_elem.send_keys(character)
time.sleep(0.1)
time.sleep(2)
browser.find_element_by_name('login').click()
try:
if WebDriverWait(browser, 5).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[1]/div[3]/div[2]/div[2]/div/div[3]/div/oc-component/div/div/div/div[2]/div[1]/div[1]/div/form/div/div/div/div/div[3]/span"))):
print('redirecting back to login')
browser.get('https://www.chegg.com/auth?action=login')
handle_captcha()
signin()
handle_captcha()
except TimeoutException:
pass
if browser.find_element_by_tag_name('h1').text == 'Oops, we\'re sorry!':
return [0]
handle_captcha()
Below is the error:
PS C:\Users\Dami\Desktop\chegg_discord_bot-master> & 'C:\Program Files (x86)\Python38-32\python.exe' 'c:\Users\Dami\.vscode\extensions\ms-python.python-2020.8.101144\pythonFiles\lib\python\debugpy\launcher' '58627' '--' 'c:\Users\Dami\Desktop\cheggDiscordBot.py'
DevTools listening on ws://127.0.0.1:58638/devtools/browser/837850c8-796e-44be-950f-49f667f48f0a
>>signing in!
Traceback (most recent call last):
File "c:\Users\Dami\Desktop\cheggDiscordBot.py", line 288, in <module>
signin()
File "c:\Users\Dami\Desktop\cheggDiscordBot.py", line 257, in signin
email_elem = browser.find_element_by_id('emailForSignIn')
File "C:\Users\Dami\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\webdriver.py",
line 360, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Users\Dami\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\webdriver.py",
line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\Dami\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\webdriver.py",
line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Dami\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, 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="emailForSignIn"]"}
(Session info: headless chrome=84.0.4147.125)