星辰幸福 2021-02-22 12:38 采纳率: 80%
浏览 310
已采纳

selenium定位无法定位网页元素

selenium打开网址之后。定位元素。

网页里这样的表格。我用了driver.find_elements_by_css_selector('[style="text-align: right;"]')[0].click()

去点击。

出错代码。

 Message: element click intercepted: Element <input type="text" class="unit sc-common-input" style="text-align: right;"> is not clickable at point (833, 869). Other element would receive the click: <div class="footer-buttons">...</div>

消息:元素单击被拦截

这个问题已经解决了。使用

div=driver.find_elements_by_css_selector('[style="text-align: right;"]')[1]
js1 ="arguments[0].scrollIntoView();" 
driver.execute_script(js1, div) 

可以定位输入。

但是出现了另外的问题,

 

.

这个页面可以定位到。

driver.find_elements_by_css_selector('[class="html-area-content"]')[0].click()

可以定位到。

但是无法传值进去

出现错误,元素不可交互。

是什么情况。

这个是html代码的输入框。

无法传值

  • 写回答

5条回答 默认 最新

  • 歇歇 2021-02-22 12:56
    关注

    您需要在该元素上使用焦点或滚动。您可能还必须使用显式等待。

     

    WebElement firstbutton= driver.findElement(By.xpath("Your Element"));
    Actions actions = new Actions(driver);
    actions.moveToElement(element);
    actions.perform();
    

     

    或者

    该元素不可点击,因为其上方有一个微调器/叠加层:

     

    By loadingImage = By.id("loading image ID");
    WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
    wait.until(ExpectedConditions.invisibilityOfElementLocated(loadingImage));
    

     

    或者

     

    Point p= element.getLocation();
    Actions actions = new Actions(driver);
    actions.moveToElement(element).movebyoffset(p.x,p.y).click().perform();
    

     

    或者

    如果仍然无法使用,请使用 JavascriptExecutor

     

    JavascriptExecutor executor = (JavascriptExecutor)driver;
    executor.executeScript("arguments[0].click();", firstbutton);
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。