【问题标题】:org.openqa.selenium.ElementNotInteractableException while clicking on span element with attribute "unselectable=on"org.openqa.selenium.ElementNotInteractableException,同时单击属性“unselectable = on”的span元素
【发布时间】:2020-11-16 14:37:49
【问题描述】:

我正在尝试什么:

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 或类。

谁能帮我解决这个问题?

【问题讨论】:

标签: java selenium selenium-webdriver xpath webdriverwait


【解决方案1】:

不可选择的属性

unSelectable 属性设置选择过程是否可以从元素的内容开始。如果一个元素的 unSelectable 属性设置为on,则该元素只有在选择开始于元素内容之外时才可选择。

在 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 样式属性是继承的。这意味着必须在所有不可选择元素上设置unSelectable 属性,无论是否在不可选择元素的父元素上设置了unSelectable 属性。


这个用例

相关的 HTML 将有助于构建规范的答案。但是,如果该元素是动态元素或网站是基于Kendo UI,则单击该元素需要诱导WebDriverWaitelementToBeClickable(),您可以使用以下Locator Strategies 之一:

  • 使用WebDriverWaitxpath

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[starts-with(., 'TrailVersion') and contains(., 'Testing_Demo')]"))).click();
    
  • 使用 Actionsxpath:

    new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[starts-with(., 'TrailVersion') and contains(., 'Testing_Demo')]")))).click().build().perform();
    
  • 使用JavascriptExecutorxpath

    ((JavascriptExecutor)driver).executeScript("arguments[0].click();", new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[starts-with(., 'TrailVersion') and contains(., 'Testing_Demo')]"))));
    

参考

您可以在以下位置找到相关的详细讨论:

【讨论】:

    猜你喜欢
    • 2018-04-02
    • 2022-01-06
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    相关资源
    最近更新 更多