java - org.openqa.selenium.ElementNotInteractableException,同时单击属性“unselectable = on”的span元素
问题描述
我正在尝试什么:
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement element = driver.findElement(By.xpath("//span[text()='TrailVersion, Testing_Demo']"));
选项1:
element.click();
选项 2:
Actions action = new Actions(driver);
action.click(element).build().perform();
action.moveToElement(element).click().build().perform();
{Giving exception "org.openqa.selenium.JavascriptException: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite." }
选项 3:
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
我想强调一下 span 标签包含<span unselectable = "on">
我已经尝试了以上所有 3 个选项的属性,但不幸的是,没有任何效果。我也为相同的元素尝试了不同的 Xpath,但徒劳无功。该元素没有唯一的 ID 或类。
谁能帮我解决这个问题?
解决方案
不可选择的属性
unSelectable属性设置选择过程是否可以从元素的内容开始。If the unSelectable attribute of an element is set to on
, then the element is selectable only if the selection starts outside the contents of the element.
在 Firefox、Google Chrome 和 Safari 中,-moz-user-select和-webkit-user-select样式属性用于实现类似的功能。
unSelectable
属性和-moz-user-select
样式-webkit-user-select
属性的区别在于-moz-user-select
,-webkit-user-select
样式属性指定是否可以选择元素,而unSelectable
属性只指定选择过程是否可以从元素的内容开始。另一个区别是unSelectable
属性不是继承的,-moz-user-select
而-webkit-user-select
style 属性是继承的。这意味着unSelectable
必须在所有不可选择元素上设置该属性,无论该unSelectable
属性是否设置在不可选择元素的父元素上。
这个用例
相关的 HTML 将有助于构建规范的答案。但是,如果元素是动态元素或网站是基于Kendo UI的,则单击需要诱导WebDriverWait的元素elementToBeClickable()
,您可以使用以下任一Locator Strategies:
使用WebDriverWait和
xpath
:new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[starts-with(., 'TrailVersion') and contains(., 'Testing_Demo')]"))).click();
使用动作和
xpath
:new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[starts-with(., 'TrailVersion') and contains(., 'Testing_Demo')]")))).click().build().perform();
使用JavascriptExecutor和
xpath
:((JavascriptExecutor)driver).executeScript("arguments[0].click();", new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[starts-with(., 'TrailVersion') and contains(., 'Testing_Demo')]"))));
参考
您可以在以下位置找到相关的详细讨论:
推荐阅读
- list - 用 Lisp 制作 Lucas 系列
- mysql - 如果列相等,则仅更新 MySQL 行
- angular - 如何将代码从 index.html 移动到组件?
- javascript - 如何将变量中的值传递给 React 组件
- sql - 对于每个时期,我需要总结时期和以前的时期
- reactjs - react 和 typescript 中的 useState() 在功能组件中丢失数据
- html5-canvas - 画布drawImage,缩小以显示整个图像
- python - 如何在 Python 中运行使用包的 Julia 文件?
- android - 需要支持从 Android 4.2 到 Android 10 的新 Android 项目可以使用 AndroidX 吗?
- javascript - 在firebase托管脚本中存储条带支付公钥是否安全