from selenium import webdriver# class ChromeDriver():# def testMethod(self):# driver = webdriver.Chrome(executable_path="C:\\Users\\nn\\PycharmProjects\\drivers\\chromedriver.exe")# driver.get("http://www.google.com")## cc = ChromeDriver()# cc.testMethod()driver = webdriver.Chrome(executable_path="C:\\Users\\nn\\PycharmProjects\\drivers\\chromedriver.exe")driver.get("http://www.google.com")
When using class in ChromeDriver, after the page is load the browser will close. Without class the browser stay on this site.
Xpath
Extension Ranorex Selocity
Inspect element
Ranorex Selocity show <input> css / xpath to copy to automation tests
Internet Explorer
Internet Explorer driver is called IEDriverServer.exe
Requirements to run tests on Internet Explorer
Set a zoom on 100%
2. Make sure that Protected Mode on every of 4 types of zone are the same (Disable or Enable)
a) Internet
b) Local intranet
c) Trusted sites
d) Restricted sites
from selenium import webdriverclassIEDriverWindows():deftestMethod(self): driver = webdriver.Ie(executable_path="C:\\Users\\nn\\PycharmProjects\\drivers\\IEDriverServer.exe") driver.get("http://www.google.com")ieObject =IEDriverWindows()ieObject.testMethod()
Safari
It's only supported on Macs. (Apple)
Commands
import webdriver
from selenium import webdriver #use a selenium package
FROM:/*<input id="displayed-text" name="show-hide" class="inputs displayed-class" placeholder="Hide/Show Example" type="text">*/input[id='displayed-text']#displayed-text/*be careful on the same id in another class*/input#displayed-textinput[class='inputs displayed-class'] /*whole name of class should be used*/.displayed-classinput.displayed-class
Appending Classes
.class1.class2.class3 -> Until we find a unique element
Wildcards in CSS Selectors
Syntax:
tag[attribute<special character>='value']
FROM:/*<input id="name" name="enter-name" class="inputs" placeholder="Enter Your Name" type="text" style="">&<input id="displayed-text" name="show-hide" class="inputs displayed-class" placeholder="Hide/Show Example" type="text" style="">*/input[class='inputs'] -> only 1 matchinginput[class^='inputs'] -> 2 matching (2 times class starts from inputs)input[class^='inp'] -> 2 matching the same like in inputsinput[class='displayed-class'] -> no maching (because not whole name of class)input[class$='class'] -> 1 matching (from displayed-class)input[class*='displayed-class'] -> 1 matching (second word of class)input[placeholder='Enter'] -> no machinginput[placeholder^='Enter'] -> 1 matching
Single slash ‘/’ anywhere in xpath signifies to look for the element immediately inside the parent element. Double slash ‘//’ signifies to look for any child or nested-‐ child element inside the parent element.
Syntax:
//tag[@attribute='value']
absolute Xpath:/html/body/header/div/div/div/div/ul/li[2]/arelative Xpath using single '/'://div[@id="navbar"]/div/div/div/ul/li[2]/aeffective(optimized)Xpath using double '//'://div[@id="navbar"]//ul/li[2]/a
contains
Syntax:
//tag[contains(attribute, ‘value’)]
//div[@id='navbar']//a[contains(text(),'Login')]//div[@id='navbar']//a[contains(@class,'navbar-‐link') and contains(@href,'sign_in')]
starts-with
Syntax:
//tag[starts-‐with(attribute, ‘value’)]
//div[@id="navbar"]//a[contains(@class, 'navbar-link')] -> 2 matching//div[@id="navbar"]//a[starts-with(@class, 'navbar-link')] -> 1 matching/*check first of class name which is using */the most shortest path is://a[@href='/sign_in']