xpath总结

切换frame

self.switch_to_frame(self.find_element_by_id('frame的id名'))
pf.ca_firstframe(selenuum_driver)

输入名称

log.info('输入模板名称')
pf.ca_input_IDP(selenium_driver, "模板名称")
pf.ca_input_IDP(selenium_driver,'简体中文',bhqz+'名字')

帮助

log.info('选择课程信息')
pf.ca_help_IDP(selenium_driver,"课程信息",1,"所有课程信息")

按钮

log.info('点击新增')
pf.ca_button_IDP(selenium_driver, "新增")

下拉框

log.info('选择使用范围')
self.find_element_by_xpath("//input[@id='dropdown_762615']/following::div[1]").click()
self.find_element_by_xpath("//tr[@text='课程信息']").click()

去空格

//*[normalize-space(text()) and normalize-space(.)='开始查询']  

键盘鼠标复杂操作

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

↓pgdn Enter按下松开

ActionChains(self.driver).key_down(Keys.DOWN).perform()
ActionChains(self.driver).key_up(Keys.DOWN).perform()
ActionChains(self.driver).key_down(Keys.ENTER).perform()
ActionChains(self.driver).key_up(Keys.ENTER).perform()

用法:

ActionChains(self.driver).key_down(Keys.XX).perform()
ActionChains(self.driver).key_up(Keys.XX).perform()

如:

ActionChains(self.driver).key_down(Keys.BACKSPACE).perform()
ActionChains(self.driver).key_up(Keys.BACKSPACE).perform()

ActionChains(self.driver).key_down(Keys.SPACE).perform()
ActionChains(self.driver).key_up(Keys.SPACE).perform()

for i in range(1,107):
    ActionChains(self.driver).key_down(Keys.DOWN).perform()
    ActionChains(self.driver).key_up(Keys.DOWN).perform()

鼠标悬停出现数据

ele2 = self.find_element_by_id("Check")
ActionChains(self.driver).move_to_element(ele2).perform()

选择表格中的数据

pf.ca_grid_Farris(driver, "dataGrid", "产品类型", bhqz + "auto", "checkbox")

关闭打开的页面

log.info('关闭成绩查询')
pf.close_menu(selenium_driver, "成绩查询")

获取属性

ele=self.find_element_by_xpath("//span[text()='银行存款']/ancestor::tr").get_attribute("index")
self.find_element_by_xpath("//div[contains(@class,'f-datagrid-body-fixed-left')]/descendant::tr[@index='%s']" % ele).click()

a_href = get_12306.find_element_by_link_text('中国铁路12306')
golbal ele
ele=a_href.get_attribute('textContent')
ele1=a_href.text
ele2=a_href.get_attribute('innerHTML')
ele3=a_href.get_attribute('outerHTML')
ele4=a_href.tag_name

在这里插入图片描述


在这里插入图片描述

button

log.info("点击另存为中的取消按钮")
pf.ca_button_Farris(selenium_driver, "取消", "另存为")

‘清空数据’

eles = self.find_elements_by_xpath('//input[@name="input-group-value"]')  输入框
dels = self.find_elements_by_xpath('//i[@class="f-icon modal_close"]')  输入框后面的x号
eles[0].click()
dels[0].click()
self.sleep(1)
eles[1].click()
dels[1].click()
self.sleep(1)
eles[2].click()
dels[2].click()

.//和//的区别
//是指从全文上下文中搜索//后面的节点,而.//则是指从前面的节点的子节点中进行查找

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值