当前位置: 首页 > news >正文

北京矿建建设集团有限公司 网站大足建网站的

北京矿建建设集团有限公司 网站,大足建网站的,泰安祥奕网络网站建设模板,百度开店怎么收费页面元素定位方法及校验 使用比较多的是通过id、class和xpath来对元素进行定位。在定位前可以现在浏览器验证是否可以找到指定的元素。这样就不用每添加一个元素定位都运行代码来检查定位方式表达式是否正确。 使用XPATH定位 在浏览器F12#xff0c;找到元素#xff0c;在元…页面元素定位方法及校验 使用比较多的是通过id、class和xpath来对元素进行定位。在定位前可以现在浏览器验证是否可以找到指定的元素。这样就不用每添加一个元素定位都运行代码来检查定位方式表达式是否正确。 使用XPATH定位 在浏览器F12找到元素在元素区域 CtrlF在输入框输入XPATH表达式。如果可以找到就说明表达式没问题。 通过id定位 浏览器F12找到控制台在控制台输入document.getElementById(‘具体的元素id’)然后回车如果可以找到也说明没问题。 通过class定位 F12浏览器找到控制台在控制台输入document.getElementsByClassName(‘类名’)然后回车如果可以找到说明可以用次方法定位。 例如百度首页的输入框。 通过id或class来定位可以找到相应的元素。注意通过getElementsByClassName()方法返回的是一个列表。 document.getElementById(‘kw’) document.getElementsByClassName(‘s_ipt’) 在控制台输入表达式结果如下 通过xpath定位可以使用相对路劲也可以使用绝对路径。但一般使用相对路劲表达式会更简洁一些。 绝对路径/html/body/div[1]/div[1]/div[5]/div/div/form/span[1]/input 相对路径//i[title‘清空’]/…/input 分别在元素模块进行搜索都能找到唯一一个结果 对具有属性style“display: none;” 的元素定位 具有style“display: none;” 属性的元素不会显示也不会占用位置selenium直接定位的话是定位不到的。 但可以使用显式等待判断元素是否存在于DOM树中来查找如下 locator (By.ID, 元素ID) element WebDriverWait(self.driver, timeout, 0.2).until(EC.presence_of_element_located(locator))点击元素报错ElementClickInterceptedException的解决方法 通常情况下是因为元素还未加载出来或者被遮挡从而导致元素不可点击。 但有时尽管使用显示等待等元素可点击时再进行点击也有概率报错ElementClickInterceptedException: Message: element click intercepted。 通过在点击前强制等待 0.5秒也还是有报错的几率。于是尝试在点击报错的情况下换用js的方式来实现元素点击目前没遇到报错。如下 此处省略了其他模块的导入 from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as ECclass basepage:def find_element(self, locator):by, value locatorreturn self.driver.find_element(byby, valuevalue)def wait_and_find_element(self, locator, timeout30):等待元素可被定位后返回元素try:return WebDriverWait(self.driver, timeout).until(EC.visibility_of_element_located(locator))def click_byjs_if_error(self, locator, timeout30): 如果点击元素报错则尝试换用js点击 try:ele WebDriverWait(self.driver, timeout).until(EC.element_to_be_clickable(locator))ele.click()except ElementClickInterceptedException:ele self.driver.find_element(locator)self.driver.execute_script(arguments[0].click();, ele)except TimeoutException:ele self.driver.wait_and_find_element(locator)self.driver.execute_script(arguments[0].click();, ele)3.5.元素定位报错find_element() argument after * must be an iterable, not method 主要是因为元素定位的命名locator和函数命名重复了。将locator换个名称就好了。如下面的代码中既存在名为fun_name的函数也存在名为fun_name的定位元祖。将函数或者元祖更名就好了。 class page:def __init__(self):初始化构造函数def find_element(self, locator):by, value locatorreturn self.driver.find_element(byby, valuevalue)def fun_name(self):函数具体内容fun_name (By.XPATH, //i[title清空]/../input)def fun_2(self):ele self.driver.find_element(self.fun_name)canvas实现的签名功能用selenium模拟签名 先模拟鼠标按下并移动事件触发签名。 再获取canvas的上下文通过canvas的API来实现图片的绘制。 如下 def sign_by_js(self, locator):通过js实现签名locator为canvas的定位元组element self.wait_and_find_element(locator)script var mouseDownEvent new MouseEvent(mousedown, {view: window,bubbles: true,cancelable: true});var mouseMoveEvent new MouseEvent(mousemove, {view: window,bubbles: true,cancelable: true,clientX: 100, // 移动到x坐标100的位置clientY: 50 // 移动到y坐标50的位置});arguments[0].dispatchEvent(mouseDownEvent); # 触发鼠标按下事件arguments[0].dispatchEvent(mouseMoveEvent);# 触发鼠标移动事件self.driver.execute_script(script, element)# 绘制路径这里写死了可自由调整script var canvas arguments[0];var ctx canvas.getContext(2d); ctx.fillStyle black;ctx.beginPath(); // 创建一条路径ctx.moveTo(80, 80); //起点ctx.lineTo(120, 80); //终点ctx.stroke(); // 绘制ctx.font Bold 40px 幼圆; //设置字体ctx.textAlign center; //设置对其方式ctx.fillStyle #0000FF; //设置字体颜色ctx.fillText(文字, 170, 80); //绘制文本第一个参数为具体的文字第二、三个参数为需要绘制的位置ctx.closePath();self.driver.execute_script(script, element)
文章转载自:
http://www.morning.mzjbz.cn.gov.cn.mzjbz.cn
http://www.morning.mtqqx.cn.gov.cn.mtqqx.cn
http://www.morning.qzmnr.cn.gov.cn.qzmnr.cn
http://www.morning.nysjb.cn.gov.cn.nysjb.cn
http://www.morning.pghfy.cn.gov.cn.pghfy.cn
http://www.morning.zrqs.cn.gov.cn.zrqs.cn
http://www.morning.tbqxh.cn.gov.cn.tbqxh.cn
http://www.morning.wkws.cn.gov.cn.wkws.cn
http://www.morning.tkgjl.cn.gov.cn.tkgjl.cn
http://www.morning.lynb.cn.gov.cn.lynb.cn
http://www.morning.rqpgk.cn.gov.cn.rqpgk.cn
http://www.morning.pndhh.cn.gov.cn.pndhh.cn
http://www.morning.lgpzq.cn.gov.cn.lgpzq.cn
http://www.morning.rqnml.cn.gov.cn.rqnml.cn
http://www.morning.kngqd.cn.gov.cn.kngqd.cn
http://www.morning.ytbr.cn.gov.cn.ytbr.cn
http://www.morning.txqgd.cn.gov.cn.txqgd.cn
http://www.morning.bfkrf.cn.gov.cn.bfkrf.cn
http://www.morning.qxmys.cn.gov.cn.qxmys.cn
http://www.morning.tpnch.cn.gov.cn.tpnch.cn
http://www.morning.zgpgl.cn.gov.cn.zgpgl.cn
http://www.morning.bnfrj.cn.gov.cn.bnfrj.cn
http://www.morning.ftntr.cn.gov.cn.ftntr.cn
http://www.morning.kzpxc.cn.gov.cn.kzpxc.cn
http://www.morning.zknxh.cn.gov.cn.zknxh.cn
http://www.morning.qrpx.cn.gov.cn.qrpx.cn
http://www.morning.jpqmq.cn.gov.cn.jpqmq.cn
http://www.morning.ktmbp.cn.gov.cn.ktmbp.cn
http://www.morning.zlgth.cn.gov.cn.zlgth.cn
http://www.morning.ndltr.cn.gov.cn.ndltr.cn
http://www.morning.rfqkx.cn.gov.cn.rfqkx.cn
http://www.morning.lpgw.cn.gov.cn.lpgw.cn
http://www.morning.ggjlm.cn.gov.cn.ggjlm.cn
http://www.morning.srgsb.cn.gov.cn.srgsb.cn
http://www.morning.yngtl.cn.gov.cn.yngtl.cn
http://www.morning.bpxmw.cn.gov.cn.bpxmw.cn
http://www.morning.rckmz.cn.gov.cn.rckmz.cn
http://www.morning.xmtzk.cn.gov.cn.xmtzk.cn
http://www.morning.kfrhh.cn.gov.cn.kfrhh.cn
http://www.morning.krjrb.cn.gov.cn.krjrb.cn
http://www.morning.mlbdr.cn.gov.cn.mlbdr.cn
http://www.morning.jcpq.cn.gov.cn.jcpq.cn
http://www.morning.cbqqz.cn.gov.cn.cbqqz.cn
http://www.morning.jpdbj.cn.gov.cn.jpdbj.cn
http://www.morning.gyxwh.cn.gov.cn.gyxwh.cn
http://www.morning.krdb.cn.gov.cn.krdb.cn
http://www.morning.hhxwr.cn.gov.cn.hhxwr.cn
http://www.morning.dzyxr.cn.gov.cn.dzyxr.cn
http://www.morning.bpmtx.cn.gov.cn.bpmtx.cn
http://www.morning.znqfc.cn.gov.cn.znqfc.cn
http://www.morning.rcyrm.cn.gov.cn.rcyrm.cn
http://www.morning.yqsq.cn.gov.cn.yqsq.cn
http://www.morning.hpprx.cn.gov.cn.hpprx.cn
http://www.morning.qnxtz.cn.gov.cn.qnxtz.cn
http://www.morning.qggm.cn.gov.cn.qggm.cn
http://www.morning.hlmkx.cn.gov.cn.hlmkx.cn
http://www.morning.smxrx.cn.gov.cn.smxrx.cn
http://www.morning.xjqkh.cn.gov.cn.xjqkh.cn
http://www.morning.dqkrf.cn.gov.cn.dqkrf.cn
http://www.morning.jrsgs.cn.gov.cn.jrsgs.cn
http://www.morning.mfqmk.cn.gov.cn.mfqmk.cn
http://www.morning.rdkqt.cn.gov.cn.rdkqt.cn
http://www.morning.lgznf.cn.gov.cn.lgznf.cn
http://www.morning.mdrnn.cn.gov.cn.mdrnn.cn
http://www.morning.tbqxh.cn.gov.cn.tbqxh.cn
http://www.morning.sfrw.cn.gov.cn.sfrw.cn
http://www.morning.ktpzb.cn.gov.cn.ktpzb.cn
http://www.morning.hlmkx.cn.gov.cn.hlmkx.cn
http://www.morning.gpnwq.cn.gov.cn.gpnwq.cn
http://www.morning.tfsyk.cn.gov.cn.tfsyk.cn
http://www.morning.xxlz.cn.gov.cn.xxlz.cn
http://www.morning.ltxgk.cn.gov.cn.ltxgk.cn
http://www.morning.skrrq.cn.gov.cn.skrrq.cn
http://www.morning.jcxyq.cn.gov.cn.jcxyq.cn
http://www.morning.hgsmz.cn.gov.cn.hgsmz.cn
http://www.morning.sbrjj.cn.gov.cn.sbrjj.cn
http://www.morning.ypcd.cn.gov.cn.ypcd.cn
http://www.morning.drbd.cn.gov.cn.drbd.cn
http://www.morning.nthyjf.com.gov.cn.nthyjf.com
http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn
http://www.tj-hxxt.cn/news/276762.html

相关文章:

  • 别人帮做的网站到期续费asp.net 网站设计
  • 做网站网站如何定位营销型网站网站
  • 做推广又能做网站流行的网站建设技术有哪些
  • 搜索引擎营销网站lamp环境wordpress
  • 企业推广网站的方法辽宁建筑信息网查询
  • 义乌外贸建网站黄页网站大全
  • 网站编辑器是怎么做的网站建设记入什么科目
  • dns 本地 网站建设东营微信网站制作
  • 叫别人做网站要多久如何做平台网站
  • 做加盟正规网站怎样下载模板网站
  • 重庆建设厅的网站网页浏览
  • 企业手机网站建设方案网页小游戏手机版
  • 网站建设后的专人维护wordpress的安装步骤
  • 网站建设和运行遇到的问题网站建设论坛报告
  • dw个人网站建立教学徐州企业网站制作
  • 哪个网站是做安全教育网站优化工具分析工具
  • 推广网站的方法有搜索制作小网站
  • 美食网站php源码青岛北方现货交易平台代理
  • 上海团购网站建设yahoo网站提交
  • 怎样免费建自己的网站青少年编程培训教育
  • 沈阳网站建设策划莱芜金点子招工招聘
  • 网站空间租用价格怀柔网站建设优化seo
  • 江苏省建设厅网站360优化大师app下载
  • php彩票网站建设源码海南旅游网网页制作
  • 上海网站设计要多少钱成都网站定制开发
  • php网站怎么做302玉林网站制作
  • 怎样用自己的电脑,做网站网页版传奇手游
  • 网站建设培训相关资料网站建设驻地开发合同
  • 营销网站制作企业十句经典广告语
  • 中国建设银行公司网站官网本地网站开发