WebDriver Basic Commands, Navigational Commands & Conditional Commands
Webdriver Basic Commands
print(driver.title) #Page Title
print(driver.current_url) #Current URL
driver.close() #close only current tab
driver.quit() #close the Browser
Script:
from selenium import webdriver
import time
driver=webdriver.Chrome(executable_path="D:\Selenium\Browsers\chromedriver_win32\chromedriver.exe")
driver.get("http://demo.automationtesting.in/Windows.html")
time.sleep(5)
print(driver.title) #page title
print(driver.current_url) #page url
driver.find_element_by_class_name("btn-info").click()
time.sleep(5)
driver.close() #current focussed tab
driver.quit() #closes browser
Navigation Commands
driver.back()
driver.forward()
Script:
from selenium import webdriver
import time
driver=webdriver.Chrome(executable_path="D:\Selenium\Browsers\chromedriver_win32\chromedriver.exe")
driver.get("http://demo.automationtesting.in/Windows.html")
time.sleep(5)
print(driver.title)
driver.get("https://www.guru99.com/testing-tools.html")
time.sleep(5)
print(driver.title)
driver.back()
time.sleep(5)
print(driver.title)
driver.forward()
time.sleep(5)
print(driver.title)
driver.quit()
Conditional Commands
is_enabled()
is_displayed()
is_selected()
Script:
from selenium import webdriver
import time
driver=webdriver.Chrome(executable_path="D:\Selenium\Browsers\chromedriver_win32\chromedriver.exe")
driver.get("https://www.facebook.com/r.php")
firstname_element=driver.find_element_by_name("firstname")
print(firstname_element.is_enabled()) #returns true/false based on element status
print(firstname_element.is_displayed()) #returns true/false based on element status
lastname_element=driver.find_element_by_name("lastname")
print(lastname_element.is_enabled()) #returns true/false based on element status
print(lastname_element.is_displayed()) #returns true/false based on element status
gender_female=driver.find_element_by_id("u_0_6")
print("status of gender female radio button",gender_female.is_selected()) #returns true/false based on element status
driver.quit()
print(driver.title) #Page Title
print(driver.current_url) #Current URL
driver.close() #close only current tab
driver.quit() #close the Browser
Script:
from selenium import webdriver
import time
driver=webdriver.Chrome(executable_path="D:\Selenium\Browsers\chromedriver_win32\chromedriver.exe")
driver.get("http://demo.automationtesting.in/Windows.html")
time.sleep(5)
print(driver.title) #page title
print(driver.current_url) #page url
driver.find_element_by_class_name("btn-info").click()
time.sleep(5)
driver.close() #current focussed tab
driver.quit() #closes browser
Navigation Commands
driver.back()
driver.forward()
Script:
from selenium import webdriver
import time
driver=webdriver.Chrome(executable_path="D:\Selenium\Browsers\chromedriver_win32\chromedriver.exe")
driver.get("http://demo.automationtesting.in/Windows.html")
time.sleep(5)
print(driver.title)
driver.get("https://www.guru99.com/testing-tools.html")
time.sleep(5)
print(driver.title)
driver.back()
time.sleep(5)
print(driver.title)
driver.forward()
time.sleep(5)
print(driver.title)
driver.quit()
Conditional Commands
is_enabled()
is_displayed()
is_selected()
Script:
from selenium import webdriver
import time
driver=webdriver.Chrome(executable_path="D:\Selenium\Browsers\chromedriver_win32\chromedriver.exe")
driver.get("https://www.facebook.com/r.php")
firstname_element=driver.find_element_by_name("firstname")
print(firstname_element.is_enabled()) #returns true/false based on element status
print(firstname_element.is_displayed()) #returns true/false based on element status
lastname_element=driver.find_element_by_name("lastname")
print(lastname_element.is_enabled()) #returns true/false based on element status
print(lastname_element.is_displayed()) #returns true/false based on element status
gender_female=driver.find_element_by_id("u_0_6")
print("status of gender female radio button",gender_female.is_selected()) #returns true/false based on element status
driver.quit()