【问题标题】:How to click a button when it is covered by tooltips of other links above the button in selenium当按钮被硒中按钮上方的其他链接的工具提示覆盖时如何单击按钮
【发布时间】:2016-03-14 17:10:04
【问题描述】:

我有一个场景,我需要单击一个按钮来编辑页面,但在这个编辑按钮上方有链接.. 当我运行代码时,鼠标会自动移动到这些链接上并屏蔽 EDIT 按钮。 任何人都可以建议我锄头点击那个按钮

【问题讨论】:

标签: selenium


【解决方案1】:

无论其状态如何,JavaScript 都会点击该元素(在您的案例中涵盖)

//Java syntax, similar in other languages
WebElement button = driver.findElement(By.id("id")); //locate the button
JavascriptExecutor js = (JavascriptExecutor)driver;  //initialize JavascriptExecutor
js.executeScript("arguments[0].click();", button);   //click the button

【讨论】:

    【解决方案2】:

    你应该隐藏你不想出现在页面上的元素,比如

    driver.execute_script(document.getElementById('THE_ID_OF_YOUR_ELEMENT').style.display='none';");
    

    如果不想使用ID,也可以使用css选择器、xpath等...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 2014-12-02
      • 1970-01-01
      • 2020-10-06
      • 2014-01-06
      • 1970-01-01
      相关资源
      最近更新 更多