6

I am trying to login to this website using my credentials. However, although I'm providing what they have in their html, it's not working

Currently, I have

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

CHROMEDRIVER_PATH = './chromedriver'

chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("--disable-blink-features")
chrome_options.add_argument("--disable-blink-features=AutomationControlled")

LOGIN_PAGE = "https://www.seekingalpha.com/login"
ACCOUNT = "account.com"
PASSWORD = "password"

driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH, chrome_options=chrome_options)
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.53 Safari/537.36'})

driver.get("https://www.seekingalpha.com/login")
username = driver.find_element_by_name("email")
username.send_keys(ACCOUNT)
password = driver.find_element_by_name("password")
password.send_keys(PASSWORD)

submit_button = driver.find_element_by_css_selector("button._60b46-2mbi1 _60b46-2LbhQ _60b46-1HfKK _60b46-qZydf _60b46-1uOHx _60b46-2NDcV _60b46-3YvwX _60b46-22lGb _60b46-1qE-_ _60b46-3DOuR _60b46-1UPRS _12b23-2JWwg _60b46-EQJB_")
submit_button.click()


driver.get("https://seekingalpha.com/article/4414043-agenus-inc-agen-ceo-garo-armen-on-q4-2020-results-earnings-call-transcript")
text_element = driver.find_elements_by_xpath('//*')

text = text_element

for t in text:
    print(t.text)

and I keep getting

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="email"]"}
  (Session info: headless chrome=90.0.4430.212)
0

3 Answers 3

6

This problem can be solved with the help of explicit wait. See the code below :

driver = webdriver.Chrome("C:\\Users\\etc\\Desktop\\Selenium+Python\\chromedriver.exe", options=options)
wait = WebDriverWait(driver, 30)
driver.get("https://www.seekingalpha.com/login")
wait.until(EC.element_to_be_clickable((By.NAME, "email"))).send_keys("some user name")
wait.until(EC.element_to_be_clickable((By.ID, "signInPasswordField"))).send_keys("your password")
wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Sign in']"))).click()
print("Logged in")

Read more about explicit wait here

Sign up to request clarification or add additional context in comments.

Comments

5

Maybe you need to wait after going to the URL for the element to appear, instead of trying immediately to identify it. You could add it like this:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# all of your current code

driver.get("https://www.seekingalpha.com/login")
username = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable(driver.find_element_by_name("email")))

username.send_keys(ACCOUNT)

# rest of your code

Comments

2

It's absolutely clear from the code you showing that you are missing wait / delay between

driver.get("https://www.seekingalpha.com/login")

and the

driver.get("https://www.seekingalpha.com/login")

lines. So, you can simply add

time.sleep(3)

there or if you wish to make it properly use something like

username = WebDriverWait(driver, 30).until(EC.element_to_be_clickable(driver.find_element_by_name("email")))

as already mentioned by C.Peck

1 Comment

The first and second lines are the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.