I have an application that generates a new browser tab when I click on a link. In the new tab I get the Chrome authentication alert. I've tried using the below code:
wd.switch_to_window(wd.window_handles[1])
a = switch_to_alert()
a.send_keys('username' + Keys.TAB + 'password')
but I get the no alert error msg
I have also tried using the ActionChain to send the keys but the alert does not receive the send_keys
Are there any alternatives?
fyi I cannot use https://username#password format as this tab is generated when I click on a link
Traceback
I suppose you mean that a link opens a new tab which has username and password fields which you input them with ‘username’ and ‘password’ respectively?
If that is the case can you on the newly opened tab first search for the elements (username and password) using an explicit wait,and only then enter values.
I had a similar issue where my web driver was stuck on the earlier page and tried inputting values into fields which didn’t exist there. Try typing your active tab’s title to confirm that’s not the case.
Related
I want to scrape a local website using selenium and need to send Username and Password to be logged in but there is no inspect element to find these elements. The website is like this:
To send keys to popup using Selenium, you can first switch your target to the popup
obj = driver.switch_to.alert
Then send keys using
obj.send_keys(username)
obj.send_keys(str(Keys.TAB)) # send a tab to go to the next field
obj.send_keys(password)
Reference: Handle alert popup inselenium
First of all, try this URL format in driver.get():
http://username:password#the-site.com
I am trying to login into openload.co using python Selenium Chrome Driver but I am getting the following error:
Message: element not interactable
I am using the following code and the error occurs in the last line of the code where I am not able to send the keys to the input tag.
from selenium import webdriver
path="path_to_chrome_driver" #add chromedriver path
driver=webdriver.Chrome(path)
from selenium.webdriver.common.keys import Keys
driver.get('https://openload.co/login')
email = driver.find_element_by_xpath('//*[#id="loginform-email"]')
email.send_keys("example#xyz.com")
I searched for the problem on stackoverflow and landed on the following link similar question which says that probably it is not pointing to correct xpath or css_selector. But I can't seem to find it.
What wrong am I doing here?
It's because there's a modal in the HTML made visible when you click the top right "Sign in" button. There's a duplication of ids. Could you try passing the password and username like this http://username:password#openload.co/ ?
#john try this, works for me:
driver.get('https://openload.co/login')
emails = driver.find_elements_by_xpath('//*[#id="loginform-email"]')
emails[1].send_keys("example#xyz.com")
Try to click on the element before sending keys.
driver.find_element_by_xpath('//*[#id="loginform-email"]').click()
Because of this the cursor will be active on the email textbox field so the element should interactivable.
There are two forms on page: first one for SignIn, second for LogIn. Both have input fields with the same #id values. You need to select form for LogIn:
email = driver.find_element_by_xpath('//h1[.="Login"]/following::*[#id="loginform-email"]')
email.send_keys("example#xyz.com")
I am using selenium to scrape twitter (not using the api's just practicing selenium) which require login when it coms to following page, am using the following code to locate the login input fields and then send the username and password string:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path="Chrome")
driver.get("https://twitter.com/login")
username = driver.find_element_by_xpath("//*[#id='page-container']/div/div[1]/form/fieldset/div[1]/input")
username.send_keys("username")
password = driver.find_element_by_xpath("//*[#id='page-container']/div/div[1]/form/fieldset/div[2]/input")
password.send_keys("password")
password.send_keys(Keys.ENTER)
driver.get("http://twitter.com/user/following")
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
the code is working except for the second field (password field) it didn't send the password strings and skips it to the next line (Keys.ENTER) and next it moves to the following page which require a login, however the cursor was at the password field which mean it already located it, strange enough there is no error message or error code when executing the script.
any thoughts what is the cause of this issue ??
am using python 2.7.6
selenium version 2.53.6
on ubuntu 14.04
thanx in advance
Instead of sending the ENTER key, just click on the Log in button. Also, your XPath is kinda brittle. I would use a more specific one or you can use the CSS selectors below.
driver.find_element_by_css_selector("#page-container input.email-input").send_keys(username);
driver.find_element_by_css_selector("#page-container input.js-password-field").send_keys(password);
driver.find_element_by_css_selector("button.submit").click();
i want to log in to uploaded.net using selenium in python. here is my code:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.uploaded.net/#login')
user = browser.find_element_by_xpath("//input[#type='text'][#name='id'][#value='Account-ID']")
user.clear()
user.send_keys("mypass")
password = browser.find_element_by_xpath("//input[#type='text'][#name='pw'][#value='Password']").click()
password.send_keys('mypass')
the problem is that, selenium successfully fill username field, but can not fill password field. i am sure selenium find password field correctly, but send_key function fail to fill password field.
does anyone know how to solve problem?
Yes. I checked uplaoded.net and it looks that input type is password (obviously), not text as you provided.
The problem is at this line:
password = browser.find_element_by_xpath("//input[#type='text'][#name='pw'][#value='Password']").click()
Once you click the element, the type changes to 'password' and therefore selenium can't send commands to an the element that you saved in password. This is sometimes called a 'stale' element because it doesn't exist on the page anymore.
You can fix this by changing your code to this:
browser.find_element_by_xpath("//input[#type='text'][#name='pw'][#value='Password']").click()
browser.find_element_by_xpath("//input[#type='password'][#name='pw'][#value='Password']").send_keys('mypass')
I am developing an automated test scripts using selenium api with python. But when i run the script from selenium rc its goes to the login page. How will I be able to put in my username and password on that page as it does not contain any sessions or cookies?
Here's the suggestion that was made to me by Adam Goucher on the Selenium IRC channel ( irc://irc.freenode.net/selenium ):
Take advantage of the situation of a completely clean browser cache/cookie history. Code your test to do the login.
However, instead of hard-coding into your code a username and password, keep a deliberately non-source-code-revisioned configuration file with the username and password locally on the client with the username and password stored there, and have your Selenium client code retrieve the username and password from there when the Selenium code executes.
Thats because selenium server starts new profile for browser everytime, so your saved cookies and bookmarks do not exist on this profile.
First create a profile, for firefox it is given here
then bundle this profile to your selenium server like this
SeleniumServer server = new SeleniumServer();
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
//rcc.setPort(4444);
File newFirefoxProfileTemplate = new File(ReadConFile.readcoFile("fiefoxProfilePath"));
rcc.setFirefoxProfileTemplate(newFirefoxProfileTemplate);
server = new SeleniumServer(rcc);
server.start();
DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*chrome",ReadConFile.readcoFile("serverName"));
to know your firefoxTemplate click here