While using the code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument('--disable-extentions')
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://www.quora.com')
user = driver.find_element_by_name('email')
user.clear()
user.send_keys('username')
password = driver.find_element_by_name('password')
password.clear()
password.send_keys('password')
driver.close()
I am getting the following error:
invalid element state: Element is not currently interactable and may not be manipulated
I think Quora has stopped automatic interactions with the login-box. Please explain how to automatically login to Quora using selenium or any other python library.
The issue is that there are multiple elements with the name email and password, instead you can select the elements using a CSS_SELECTOR like so:
user = driver.find_element_by_css_selector('.regular_login [name=email]')
user.clear()
user.send_keys('username')
password = driver.find_element_by_css_selector('.regular_login [name=password]')
password.clear()
password.send_keys('password')
There are 2 elements with the name email and password on the Quora login page. One is intractable and one is not.
It appears the one that is not clickable is only displayed on signup.
In order to get the correct elements for the normal login the following xpaths were working for me:
user = driver.find_element_by_xpath("//div[#class='regular_login']//input[#name='email']")
password = driver.find_element_by_xpath("//div[#class='regular_login']//input[#name='password']")
Check if your xpth is unique. You can use chropath or pagemodellor to get a unique xpath or build one on your own. Otherwise, this is straightforward solution to click
always test your xpath twice before using it so you save time before its late.
//tag[#name='somename']
Related
So, the last 3 hours or so I have tried to get Selenium to work without success. I managed to make it work with requests and Beautifulsoup, but apparently site uses javascript to load data after login so I cannot scrape the data I want after successful login.
Below is the script I am trying to work with.
``
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
driver = webdriver.Chrome("/home/user/Desktop/chromedriver")
username = "FakeUsername"
password = "PasswordFake"
driver.get("https://www.helen.fi/kirjautuminen")
time.sleep(10)
# find username/email field and send the username itself to the input field
# find password input field and insert password as well
driver.find_element(By.XPATH,'//input[#id="username"]').send_Keys(username)
# click login button
``
(Yes, I know its missing password and submit actions, but I can't get it to write anything into username or password input boxes. Also same script seems to be working fine with github's login page, so I really can't understand what I am doing wrong here).
After running the script, chrome opens, site loads fine, but for some reason I get error
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[#id="username"]"}
I have tried with element ID and Name with similar errors, except it said something about "unable to locate element: css selector ..."
If anyone has some advice to give a newbie, it would be awesome. This is starting to give me headache.
I except the script to write username into username input box, but nothing happens.
this occurs because there is an iframe in the page code. It is necessary to switch to the iframe and then search for the element, follow the code with the correction.
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path= "chromedriver.exe")
username = "FakeUsername"
password = "PasswordFake"
driver.get("https://www.helen.fi/kirjautuminen")
# find username/email field and send the username itself to the input field
# find password input field and insert password as well
iframe = driver.find_element(By.XPATH, '//iframe[#class="login-iframe"]')
driver.switch_to.frame(iframe)
driver.find_element(By.XPATH,'//input[#id="username"]').send_keys(username)
# click login button
I am trying to use Selenium to sign up an email account automatically whenever I need to. It's just a fun learning project for me. For the life of me I don't understand why it can't find the element. This code works fine on the sign-in page but not the sign-up page. I have tried all different Selenium commands and even tried using the ID and class name. Either is says it can't locate the element or that it is not reachable by keyboard.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import time
options = Options()
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe')
driver.get("https://mail.protonmail.com/create/new?language=en")
time.sleep(10)
username_input = driver.find_element_by_id("username").send_keys("testusername")
Also here is the HTML code: https://i.imgur.com/ZaBMTzG.png
The username field is in iframe, you need to switch to iframe to make this work.
Below is the code that works fine :
driver.get("https://mail.protonmail.com/create/new?language=en")
driver.switch_to.frame(driver.find_element_by_css_selector("iframe[title='Registration form'][class='top']"))
driver.find_element_by_id("username").send_keys("some string")
read more about iframe here
learn more about how to switch to iframe/frame/framset using Python
selenium Bindings here
Update :
wait = WebDriverWait(driver, 30)
driver.get("https://mail.protonmail.com/create/new?language=en")
driver.switch_to.frame(driver.find_element_by_css_selector("iframe[title='Registration form'][class='top']"))
driver.find_element_by_id("username").send_keys("some string")
driver.switch_to.default_content()
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
sleep(5)
driver.switch_to.frame(driver.find_element_by_css_selector("iframe[title='Registration form'][class='bottom']"))
wait.until(EC.element_to_be_clickable((By.NAME, "submitBtn"))).click()
I'm not sure if I've seen enough code to diagnose, but I think the way you are defining username_input seems problematic. driver.find_element_by_id("username").send_keys("testusername") doesn't actually return anything so it seems like you are setting username_input = null.
I used below scripts to log into the following website with a username and password. It used to work fine. However, I think recently Etsy set the username ( and maybe password too) to hidden type. So username cannot be sent to the Email address field. Here are the scripts. Anyone knows how to fix this particular case?
The error message is:
ElementNotVisibleException: Message: element not visible
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument('--kiosk-printing')
self.driver = webdriver.Chrome('C:/Python27/chromedriver.exe',chrome_options=chrome_options)
self.driver.get("https://www.etsy.com/signin")
usernameFieldID = "username"
passFieldID = "password"
signButtonXpath = "//input[#value='Sign in']"
usernameFieldElement = WebDriverWait(driver, 5).until(lambda driver:driver.find_element_by_name(usernameFieldID))
passFieldElement = WebDriverWait(driver, 5).until(lambda driver:driver.find_element_by_name(passFieldID))
signButtonElement = WebDriverWait(driver, 5).until(lambda driver:driver.find_element_by_xpath(signButtonXpath))
usernameFieldElement.send_keys("abc#abc.com")
passFieldElement.send_keys("EtsyPass")
signButtonElement.click()
You need to consider a certain factors as follows :
As the fields/elements pertaining to Email address, Password and Sign in button is on the same page, you don't have to induce WebDriverWait for all the individual fields. Inducing WebDriverWait on the first field will provide ample time for all the elements to be interactive within the HTML DOM.
As you will be working with multiple elements on the Web Page instead of until(lambda) you need to get more granular with expected_conditions
Down the lane as you are trying to invoke send_keys("foo") you can consider using expected_conditions as element_to_be_clickable.
Here is the working code :
self.driver.get("https://www.etsy.com/signin")
WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#class='input input-large ' and #id='join_neu_email_field']"))).send_keys("abc#abc.com")
self.driver.find_element_by_xpath("//input[#class='input input-large ' and #id='join_neu_password_field']").send_keys("EtsyPass")
self.driver.find_element_by_xpath("//button[#class='btn btn-large width-full btn-primary' and #name='submit_attempt']").click()
For the Button not being clicked, there are two possible reasons making your script fails.
Timing:
I suppose that the button is disabled until both email and password are filled. That makes that you have to wait till the button is enabled. To test if this is the reason of failure you can put sleep just before clicking on the button.
Your locator is not unique:
Did you check using, for instance, Chrome Developer tools that your locator for the submit button is unique? If not, another element (not visible on your page) is maybe clicked.
How to do this you can learn here: https://www.youtube.com/watch?v=GMk7ZLuo6Po.
I've solved the problem with my original code by adding
time.sleep(5) after the click button command was executed.
I think Chrome takes time to feed in the login ID and password. Without the extra time, the next line was executed without logging in yet.
Thanks everyone, for your handy tips.
I want to use Selenium within Python to login to a website and then download some freely available information once per day to monitor how it changes over time.
The website has registration and login next to each other, and both use the same id
My code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('http://www.acquirersmultiple.com/login/')
#login_user = browser.find_element_by_css_selector('.rcp_login_data > p:nth-child(1) > input:nth-child(2)')
username = browser.find_element_by_id("rcp_user_login")
password = browser.find_element_by_id('rcp_user_pass')
username.send_keys("SomeUser")
password.send_keys("P4s5word")
Results in SomeUser as username on the website in the registration field, not the login.
I tried selecting by css selector, no luck there either.
The login fields are under the login form. You can locate the form and use it to locate the fields
login_form = browser.find_element_by_id('rcp_login_form')
username = login_form.find_element_by_id('rcp_user_login')
password = login_form.find_element_by_id('rcp_user_pass')
Or use it in the locator
username = browser.find_element_by_css_selector('#rcp_login_form #rcp_user_login')
password = browser.find_element_by_css_selector('#rcp_login_form #rcp_user_pass')
This is how I do it, when I don't find unique element using id or name.
Go to it's parent folder and check if that's uniquely identifiable if not go to it's parent until you find the element. And then form an xpath.
For you the xpath for usename and passwod will look like this.
//form[#id='rcp_login_form']//*[#name='rcp_user_login']
//form[#id='rcp_login_form']//*[#name='rcp_user_pass']
Here is the Answer to your Question:
You have used the locator id to locate the elements Username and Password fields from the Subscriber Login section, but those locators are not unique across the HTML DOM. We need to construct unique xpath which can identify the elements. You can use the following code block:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
browser = webdriver.Firefox(firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
browser.get('http://www.acquirersmultiple.com/login/')
browser.execute_script("window.scrollTo(0, 400);")
username = browser.find_element_by_xpath("//form[#id='rcp_login_form']//input[#id='rcp_user_login']")
password = browser.find_element_by_xpath("//form[#id='rcp_login_form']//input[#id='rcp_user_pass']")
username.send_keys("SomeUser")
password.send_keys("P4s5word")
Let me know if this Answers your Question.
CSS Selector solution:
username = browser.find_element_by_css_selector("form#rcp_login_form input#rcp_user_login")
password = browser.find_element_by_css_selector('form#rcp_login_form input#rcp_user_pass')
I am trying to use selenium to log into this website:
but it says the password and login are not visible. I looked around and saw that some people said to wait, but waiting does not seem to help. Here is my code:
# importing libraries
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import re, time, csv
driver = webdriver.Firefox()
driver.get("https://platform.openquake.org/account/login/")
driver.switch_to
driver.maximize_window
time.sleep(10)
username = driver.find_element_by_xpath("//input[#name='username']")
username.send_keys("hi there")
Error message is :
ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Your XPATH actually matches two elements. The non-plural driver methods (find_element_by_XXX) return the first element they find a match for, which in this case is not the one you want.
A good debugging tool for situations like this is to use the plural forms (find_elements_by_XXX) and then see how many elements matched.
In this case, you should do what Tanu suggested and use a more restrictive XPATH:
username = driver.find_element_by_xpath("//div[#class='controls']/input[#id='id_username']")
password = driver.find_element_by_xpath("//div[#class='controls']/input[#id='id_password']")
Modify your xpath:
username = driver.find_element_by_xpath("//div[#class='controls']/input[#id='id_username']")