Headless Browser using PhantomJS

You will learn how to execute your scripts in Headless browser using PhantomJS.

Scenario :
Enter UserName and Password
Click on the Login button.
Verify the Window Title
Close the browser

Precondition: You should download the PhantomJS.exe from below URL


Script:

from selenium import webdriver
#below is the path where phantomjs.exe file is located.
driver=webdriver.PhantomJS(
"C:\\Softwares\\phantomjs\\bin\\phantomjs.exe")
driver.get(
"http://newtours.demoaut.com")
driver.find_element_by_name(
"userName").send_keys("hello")
driver.find_element_by_name(
"password").send_keys("hello")
driver.find_element_by_name(
"login").click()
print(driver.title)
driver.close()


Note: You will get below warning while executing the script
User Warning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead

Comments