Reputation: 13
I'm trying to automate login on a few quora accounts to check their revenue.
I'm getting stuck at the first part: the login screen.
I have tried using css_selector, xpath, and name. My problem is the way that the quora login page is set up, the xpath is NEW for every new instance of it, so there is no way to select the element by this.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1200x600')
driver = webdriver.Chrome(options=options)
driver.get('https://quora.com')
driver.implicitly_wait(3)
email = driver.find_element_by_css_selector('input[type=password]')
password = driver.find_element_by_css_selector('input[type=password]')
login = driver.find_element_by_css_selector('input[value="Login"]')
email.send_keys('')
password.send_keys('')
driver.get_screenshot_as_file('main-page.png')
is what i have so far.
Can anyone look at www.quora.com and figure out which element I should be targeting in order to fill out the form and submit it? Because I've tried for over an hour at this point with no success because nothing works.
Upvotes: 0
Views: 33
Reputation: 167992
Your problem is in wrong selectors
input[type=password]
selector 2 times which is not correct as you should have different selectors for email and password inputsYour selector matches 2 elements as it's evidenced by Chrome Developer Tools
therefore Selenium tries to send keys to 1st one which is not visible/interactable
So make sure to:
Use selectors which identify elements in clear and unique manner, this way you will have confidence that you're working with the element you're expecting, i.e. stick to Placeholder
attribute
email = driver.find_element_by_css_selector('input[Placeholder=Email]')
password = driver.find_element_by_css_selector('input[Placeholder=Password]')
During test development it's better to use "normal" browser so you could observe what's going on as the test runs
Upvotes: 1