python+selenium-- 定位table表格


定位table表格

 

 Table 表格固定格式:./*[@id='表格id']/tbody/tr[行数]/td[列数]/a

from selenium import webdriver from time import sleep driver = webdriver.Firefox() driver.get("http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html") driver.implicitly_wait(10) #登录
driver.find_element_by_xpath(".//*[@id='account']").send_keys("admin") driver.find_element_by_xpath(".//*[@name='password']").send_keys("123456") sleep(2) driver.find_element_by_xpath(".//*[@id='submit']").click() sleep(5) driver.get("http://127.0.0.1/zentao/bug-browse-1.html") sleep(3) table = ".//*[@id='bugList']/tbody/tr[3]/td[4]/a" driver.find_element_by_xpath(table).click() sleep(3) driver.close()

 

根据表格名称定位后边按钮

 

from selenium import webdriver from time import sleep driver = webdriver.Firefox() driver.get("http://127.0.0.1/zentao/user-login-L3plbnRhby8=.html") driver.implicitly_wait(10) # 登录
driver.find_element_by_xpath(".//*[@id='account']").send_keys("admin") driver.find_element_by_xpath(".//*[@name='password']").send_keys("123456") sleep(2) driver.find_element_by_xpath(".//*[@id='submit']").click() sleep(5) # 先定位bug标题,在定位父节点之后再定位编辑按钮
 driver.get("http://127.0.0.1/zentao/bug-browse-1.html") sleep(3) title = "TestBug02"
#先通过bug标题定位,..为父级 再定位父级的父级,再定位td标签下a标签的编辑按钮
t = ".//*[text()='%s']/../../td[@class='text-right']/a[@title='编辑']" % title driver.find_element_by_xpath(t).click() sleep(3) driver.close()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM