Created
April 29, 2017 08:42
-
-
Save anonymous/6c79fde9d57b7d24c0b6e4996afb7101 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver #Importing the web driver from selenium library | |
browser = webdriver.PhantomJS(executable_path=r'C:\Python27\phantomjs-2.1.1-windows\bin\phantomjs.exe') #Setting our virtual browser with PhantomJS. | |
#Note: If file path of phantomjs path is not set then we need to pass its executable_path as argument. In windows phantomjs.exe and phantomjs otherwise. | |
browser.set_window_size(1120, 550) #Resize the browser to desired size. Try out this code by removing this line and see the screenshot. | |
browser.get("http://testing-ground.scraping.pro/login") #Getting the response from http://testing-ground.scraping.pro/login. | |
#Go to this URL and see expectations also explore the dom structure of the page. | |
browser.find_element_by_id('usr').send_keys("admin") #Finding input box of username by its id and sending 'admin' as a user name. | |
browser.find_element_by_id('pwd').send_keys("12345") #Finding input box of the password by its id and sending '12345' as a password. | |
browser.find_element_by_xpath("//*[@id='case_login']/form/input[3]").click() #Click the login button by finding it using its xpath. | |
browser.save_screenshot('credential_check.png') #Taking a screenshot of the browser and saving it as 'credential_check.png' file. | |
browser.quit() #And quit the browser at the end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment