python+selenium 定位元素踩过的坑

1、隐藏的元素
定位一组元素,发现报错:selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
检查写的定位方法没发现问题,后来发现页面上只有3个找出来有9个。
加上代码显示成功了,原来元素有些是隐藏的,虽然没搞明白为啥有隐藏的

# for input_ in inputs1:
#     if input_.get_attribute("text") == "1" and input_.is_displayed():
#         input_.click()

2、动态模窗DIIV
一个div窗口的元素怎么也定位不到,也不是多个窗口,就是当前的窗口,也不是要切换iframe,也不是asert最后才知道,要用方法driver.switch_to_default_content()定位,定位到当前最顶层DIV

driver.switch_to_default_content()

3、出现点击位置被覆盖从而点击错误的问题,报错:selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element … is not clickable at point (832, 287). Other element would receive the click: <input type=“text” autocomplete=“off” class="el-input__i
方法一:js注入

ele=driver.find_element_by_xpath("//span[text()='确认修改']")
driver.execute_script("arguments[0].click();", ele)

方法二:ActionChains,需要先导入
element = driver.find_element_by_css(‘div[class*=“loadingWhiteBox”]’)
webdriver.ActionChains(driver).move_to_element(element ).click(element ).perform()

方法三:使用回车代替点击
driver.find_element(By.CSS_SELECTOR,"#submit").send_keys(Keys.ENTER)

4、报错:selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted,有其他元素覆盖了元素定位

element=driver.find_element_by_xpath("//p[text()='标记问题卷']")
driver.execute_script("arguments[0].click()",element)

5、接上条,定位到了元素,点击了页面却无响应,加上time.sleep(5),就可以了,原因是页面虽然看到了那个元素,但是有些数据可能还没有加载出来,所以需要设置强制等待。

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值