I'm using selenium in python to check the page of a website that uses basic authentication on one frame. I'm checking to see if the password I am entering is correct or not, so the basic authentication often gets stuck because the password is wrong. Normally I use sel.set_page_load_timeout(8) and then catch the exception thrown when the page takes too long, but because the page loads except for the one frame, this function is not throwing an exception, and the page is getting stuck. How can I break out of the page?
Solution: go to the url of the frame itself, and set page load timeout on that page
Related
I'm having a problem when trying to login to target.com with selenium. I have used firefox and chromium webdriver. It's always success with the browser that opened manually. But with selenium, it always failed.
The error happens when I submit the login form. It says "error T83072242".
I have attached the AJAX response that I get here.
After doing some analysis, I got a conclusion that these variable on request header is the one that caused the error. When I replace this variable with the one from the another browser(that I open manually), the ajax request is success.
So, how to make the selenium-browser behave like the normal browser?
Pardon for my english.
I'm adding authentication to an existing pyramid project. The simplest form that I'm currently trying (will be expending later) is for all pages to raise HTTPForbidden. The exception view is /login, which will ask for login details and, on success, return HTTPFound with request.referer as the location.
So far so good, this does what I want, which is bringing users back to the page they were trying to access when the login page interrupted them. Let's call this Page A.
The login page is a simple HTML form with a submit button.
However if the user mistypes username or password, I want to return to the login page with an error message saying "Wrong password" or similar. When that happens, request.referer is now the login page instead of Page A.
How do I 'store' Page A (or rather its URL) so that, when the user eventually succeeds in logging in, they find themselves back on Page A? Is the session used for things like this, and are there non-session ways of implementing it? I don't (yet) have a session for this simple page, and am trying to avoid adding different components in one pass.
I recommend you to pass a parameter like login/?next=pageA.html
If the login fails, you could then forward your parameter next to /login again, even if the referrer points now to /login.
Then when the user will successfully log in, you could redirect if to pageA.html that will be held in your next parameter.
You will indeed need to check if your parameter next is a valid one, as someone could copy-paste or try to tamper with this parameter.
I am trying to login into a website using Selenium. The website is http://projecteuler.net/login.
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://projecteuler.net/login')
username = browser.find_element_by_id('username')
username.send_keys(USERNAME_HERE)
password = browser.find_element_by_name('password')
password.send_keys(PASSWORD_HERE)
browser.find_element_by_name("login").submit()
The program is working correctly upto the last statement. I tried omitting the last statement and manually logged in and it worked. But when I added the last statement and ran the program it just seemed to reload the same page minus the information that I had placed via the program.
So it is only the submission that is giving problem. I viewed the source and confirmed whether there is some other element by that name but there was no other element by name "login". So what am I getting wrong here? Do I need to take care of something else also?
There is a weird thing happening. When I have done form submission via code and try to view the source in Google Chrome 33.0.1750.154 m I am getting the below.
Try click() instead of submit()
Submit is particularly useful for forms without submit buttons, e.g. single-input “Search” forms.
Source:-
http://selenium.googlecode.com/git/docs/api/py/selenium/selenium.selenium.html?highlight=submit#selenium.selenium.selenium.submit
In your case there is a submit button, better to just click it.
I'm trying to get definitions of words using Google and urllib2 by opening this url, https://www.google.com/search?q=define+<something> and parsing the source for the definition. However, when I try to access the page I get a 403 Error, supposedly to prevent data mining in this sort of fasion. I'm fairly sure it wouldn't be wise to try and bypass that, so i'm wondering if there's an alternative for accessing data from Google's servers, or a data dump I should be using.
Edit: Here is the extent of the code i'm using to access the URL;
url = "https://www.google.com/search?q=define+" + word
try:
source = ulib.urlopen(url)
except ulib.HTTPError, e:
print e.fp.read()
We would need to see your code for confirmation, but your question was probably answered here. In a nutshell, you need to define your user agent.
I'm trying to get some data from a webpage, but I found a problem. Whenever I want to go to the next page (i.e. page 2) to keep retrieving the data on it, I keep receiving the data from page 1. Apparently something goes wrong trying to switch to the next page.
The thing is, I haven't had problems with urls like this:
'http://www.webpage.com/index.php?page=' + str(pageno)
I can just start a while statement and I'll just jump to page 2 by adding 1 to "pageno"
My problem comes in when I try to open an url with this format:
'http://www.webpage.com/search/?show_all=1#sort_order=ASC&page=' + str(pageno)
As
urllib2.urlopen('http://www.webpage.com/search/?show_all=1#sort_order=ASC&page=4').read()
will retrieve the source code from http://www.webpage.com/search/?show_all=1
There is no other way to retrieve other pages without using the hash, as far as I'm concerned.
I guess it's just urllib2 ignoring the hash, as it is normally used to specify a starting point for a browser.
The fragment of the url after the hash (#) symbol is for client-side handling and isn't actually sent to the webserver. My guess is there is some javascript on the page that requests the correct data from the server using AJAX, and you need to figure out what URL is used for that.
If you use chrome you can watch the Network tab of the developer tools and see what URLs are requested when you click the link to go to page two in your browser.
that's because hash are not part of the url that is sent to the server, it's a fragment identifier that is used to identify elements inside the page. Some websites misused the hash fragment for JavaScript hook for identifying pages though. You'll either need to be able to execute the JavaScript on the page or you'll need to reverse engineer the JavaScript and emulate the true search request that is being made, presumably through ajax. Firebug's Net tab will be really useful for this.