gpt4 book ai didi

java - 单击菜单链接时获取元素不可单击异常

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:40:13 25 4
gpt4 key购买 nike

我想点击菜单链接,但没有成功。它总是显示异常-

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (64, 64). Other element would receive the click: < div style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 30; background-color: rgb(221, 221, 221); opacity: 0.4;">

我关注 html片段

<div id="RWR" class="clsDesktopHome" style="position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; overflow: auto;">
<div class="clsDesktop clsDesktopHomePage" style="width: 1553px; height: 430px; top: 0px; left: 15px;">
<div id="foid:2" class="clsDesktopHeader clsTextOnDesktopColor">
<div id="foid:1" class="clsDesktopTabs" style="margin-right: 230px; height: 28px; visibility: visible; width: auto;">
<span class="clsDesktopTab clsDesktopTabActive clsDesktopTabTypeHome clsDesktopTabTypeHomeActive">
<span class="clsDesktopTabContent">
<span class="clsDesktopTabTypeIcon"></span>
<span class="clsDesktopTabMenuIcon"></span>
<span class="clsDesktopTabCollaborationIcon"></span>
<span class="clsDesktopTabCaption">Home</span>
<span class="clsDesktopTabCloseIcon"></span>
</span>
</span>
<span class="clsDesktopTab clsDesktopTabInactive clsDesktopTabCanClose clsDesktopTabTypeSheet">
<span class="clsDesktopTab clsDesktopTabInactive clsDesktopTabCanClose clsDesktopTabTypeSheet">
<span class="clsDesktopTab clsDesktopTabInactive clsDesktopTabCanClose clsDesktopTabTypeSheet">
<span class="clsDesktopTab clsDesktopTabInactive clsDesktopTabCanClose clsDesktopTabTypeSheet">
<span class="clsDesktopTab clsDesktopTabInactive clsDesktopTabCanClose clsDesktopTabTypeSheet">
<span class="clsDesktopTab clsDesktopTabInactive clsDesktopTabCanClose clsDesktopTabTypeSheet">
<span class="clsDesktopTab clsDesktopTabInactive clsDesktopTabCanClose clsDesktopTabTypeSheet">
<span class="clsDesktopTab clsDesktopTabHidden clsDesktopTabNoCaption clsDesktopTabTypeTabsMenu">
<span class="clsDesktopTab clsDesktopTabInactive clsAddNewContainer clsDesktopTabTypeAddNew">
</div>
<div class="clsDesktopBelowTabs" style="height: 325px; visibility: visible;">
<div id="foid:2" class="clsDesktopFooter clsTextOnDesktopColor" style="height: 18px; line-height: 18px;">
</div>
<div class="clsModalNode" style="position: absolute; left: 0px; top: 0px; width: 0px; height: 0px; z-index: 10; background-color: rgb(0, 0, 0);"></div>
<div style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 30; background-color: rgb(221, 221, 221); opacity: 0.4; display: none;"></div>
</div>

这是快照的样子-

enter image description here

我正在使用以下代码来完成相同的任务 -

    WebElement element = driver.findElement(By.xpath(".//*[@id='foid:1']/span[1]/span/span[4]"));
WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.elementToBeClickable(element));

//driver.findElement(By.xpath("//span[contains(text(), 'Home')]")).click();

driver.findElement(By.xpath(".//*[@id='foid:1']/span[1]/span/span[4]")).click();

我确实检查了 <div> DOM 中接受点击的标记。但是我看到了这个

<div style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 30; background-color: rgb(221, 221, 221); opacity: 0.4;"></div>

具有一个附加属性,即 display:none;

使用以下配置:

  1. Selenium 3.0.1
  2. 司机 - ChromeDriver

我不知道如何处理这种情况。

最佳答案

尝试等到获得点击的元素消失:

new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath('//div[@style="position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; z-index: 30; background-color: rgb(221, 221, 221); opacity: 0.4;"]')));

由于这个答案被否决了,我添加了一些更多的细节来解释为什么它是可以接受的解决方案。

这是 chromedriver 的一个已知问题(我个人遇到过几次):chromedriver 有时会忽略模态窗口,例如“Page loading in progress”

enter image description here

并“认为”目标元素(被模态窗口覆盖)实际上可见且可点击,并尝试使模态窗口接收到点击。

所以等待模态窗口消失是有意义的。

关于java - 单击菜单链接时获取元素不可单击异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41632230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com