• // : Select current node.
  • Tagname: Tagname of the particular node.
  • @: Select attribute.
  • Attribute: Attribute name of the node.
  • Value: Value of the attribute.
from selenium.webdriver.common.by import By

Xpath=//tagname[@attribute='value']
Xpath=//input[@name='uid']
Xpath=//input[@type='text']				
Xpath=	//label[@id='message23']
Xpath=	//input[@value='RESET']
Xpath=//*[@class='barone']
Xpath=//a[@href='http://demo.guru99.com/']
Xpath= //img[@src='//guru99.com/images/home/java.png']
Xpath=//*[contains(@type,'sub')]
Xpath=//*[contains(@name,'btn')]
Xpath=//*[contains(@id,'message')]Xpath=//*[contains(text(),'here')]
Xpath=//*[contains(@href,'guru99.com')]
Xpath=//*[@type='submit' or @name='btnReset']
Xpath=//input[@type='submit' and @name='btnLogin']
Xpath=//label[starts-with(@id,'message')]
Xpath=//td[text()='UserID']
Xpath=//*[@type='text']//following::input
Xpath=//*[@type='text']//following::input[1]
Xpath=//*[text()='Enterprise Testing']//ancestor::div
Xpath=//*[text()='Enterprise Testing']//ancestor::div[1]
Xpath=//*[@id='java_technologies']//child::li
Xpath=//*[@id='java_technologies']//child::li[1]
Xpath=//*[@type='submit']//preceding::input
Xpath=//*[@type='submit']//preceding::input[1] 
xpath=//*[@type='submit']//following-sibling::input
Xpath=//*[@id='rt-feature']//parent::div
Xpath=//*[@id='rt-feature']//parent::div[1]
Xpath =//*[@type='password']//self::input
Xpath=//*[@id='rt-feature']//descendant::a
Xpath=//*[@id='rt-feature']//descendant::a[1]

 

 

  • Using class_name:

    button = driver.find_element_by_class_name("quiz_button")
    

    Needs be replaced with:

    button = driver.find_element(By.CLASS_NAME, "quiz_button")
  • Using id:

    element = find_element_by_id("element_id")
    

    Needs be replaced with:

    element = driver.find_element(By.ID, "element_id")
    
  • Using name:

    element = find_element_by_name("element_name")
    

    Needs be replaced with:

    element = driver.find_element(By.NAME, "element_name")
    
  • Using link_text:

    element = find_element_by_link_text("element_link_text")
    

    Needs be replaced with:

    element = driver.find_element(By.LINK_TEXT, "element_link_text")
    
  • Using partial_link_text:

    element = find_element_by_partial_link_text("element_partial_link_text")
    

    Needs be replaced with:

    element = driver.find_element(By.PARTIAL_LINK_TEXT, "element_partial_link_text")
    
  • Using tag_name:

    element = find_element_by_tag_name("element_tag_name")
    

    Needs be replaced with:

    element = driver.find_element(By.TAG_NAME, "element_tag_name")
    
  • Using css_selector:

    element = find_element_by_css_selector("element_css_selector")
    

    Needs be replaced with:

    element = driver.find_element(By.CSS_SELECTOR, "element_css_selector")
    
  • Using xpath:

    element = find_element_by_xpath("element_xpath")
    

    Needs be replaced with:

    element = driver.find_element(By.XPATH, "element_xpath")

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 MonkeyJ 的頭像
    MonkeyJ

    程式猴

    MonkeyJ 發表在 痞客邦 留言(0) 人氣()