selenium 常用總結

去tr裏面的內容

text = driver.find_elements_by_xpath("//table[@id='trackTable']")

for i in text:

  print i.text




#下拉框

#Select(driver.find_element_by_id("set_start_hour_scan")).select_by_index(3)

#Select(driver.find_element_by_id("set_start_hour_scan")).select_by_value("11")

#Select(driver.find_element_by_id("set_start_hour_scan")).select_by_visible_text("18")


xpath常用的複雜方法

1. 使用starts-with

//div[starts-with(@id,'aaaa')]//table//tr//td[2]//table//tr//td//a//span[contains(.,'fffffffff')]

2.使用contains和and

//div[starts-with(@id,'res')]//table[1]//tr//td[2]//a//span[contains(.,'ffffffffft') and contains(.,'fffffffff')]

3.使用descendant

//div[starts-with(@id,'res')]//table[1]//tr//td[2]//a//span[contains(.,'QuickStart')]/../../../descendant::img

4.使用ancestor

//div[starts-with(@id,'res')]//table[1]//tr//td[2]//a//span[contains(.,'QuickStart')]/ancestor::div[starts-with(@id,'res')]//table[2]//descendant::a[2]

5.使用text()

//span[@id='idHeaderTitleCell' and contains(text(),'QuickStart')]


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章