Reputation: 29
I am trying to use selenium webdriver (python) with phantomJS to automate some boring administrative stuff that is done on a particular website. The website has a basic http auth mechanism. I run the following code but I am not getting anything (i.e nothing in screen.png or title). When I connect using wget using the same format (https://username:[email protected]) it works and I get the initial homepage that should be shown on successful login. How do I debug this.. Is there a way to turn on verbosity so I can see what is is really getting. Also please note that using firefox or any other UI webdriver is not an option as I want to only run it from a linux box inside the firewall.
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import getpass
login = "myname"
password = getpass.getpass("Enter password")
password = password.replace("@","%40")
url = "https://%s:%[email protected]/"%(login,password)
print url
# Create a new instance of the Firefox driver
driver = webdriver.PhantomJS('./phantomjs/bin/phantomjs')
# go to the website
driver.get(url)
driver.save_screenshot('screen.png')
# the page is ajaxy so the title is originally this:o
print driver.title
driver.set_window_size(1024, 768)
driver.get_screenshot_as_png()
Thanks
Upvotes: 1
Views: 1951
Reputation: 26
as the variant:
password.replace()
to urllib.quote()
since there could be more than @
special symbols in password.driver.get()
use previously imported EC for waiting for some element on the page and only after that - take screenshot.Upvotes: 1