org.openqa.selenium.ElementNotInteractableException while clicking on span element with attribute "unselectable=on"

huangapple 未分类评论47阅读模式
英文:

org.openqa.selenium.ElementNotInteractableException while clicking on span element with attribute "unselectable=on"

问题

我正在尝试的内容

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(); 

{出现异常 "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">`
我已经尝试了以上的三个选项但不幸的是都没有起作用我还尝试了不同的 Xpath 来定位相同的元素但都没有成功该元素没有唯一的 ID 或类名

有谁可以帮助我解决这个问题吗
英文:

What I am trying:

driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement element = driver.findElement(By.xpath(&quot;//span[text()=&#39;TrailVersion, Testing_Demo&#39;]&quot;));

Option 1:

element.click();

Option 2:

Actions action = new Actions(driver);
action.click(element).build().perform();
action.moveToElement(element).click().build().perform(); 

  {Giving exception &quot;org.openqa.selenium.JavascriptException: javascript error: Failed to execute &#39;elementsFromPoint&#39; on &#39;Document&#39;: The provided double value is non-finite.&quot; }

Option 3:

JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript(&quot;arguments[0].click();&quot;, element);

I would like to highlight that span tag contains attribute &lt;span unselectable = &quot;on&quot;&gt;
I have tried all the above 3 options but unfortunately, nothing is working. I have tried different Xpath's for the same element too but in vain. The element has no unique ID or class.

Can anyone please help me resolve the issue?

答案1

得分: 0

unSelectable 属性

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,那么要点击该元素,您需要使用 WebDriverWait 等待 elementToBeClickable(),并且可以使用以下任一 定位策略

  • 使用 WebDriverWaitxpath

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

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

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

参考

您可以在以下链接中找到相关的详细讨论:

英文:

unSelectable attribute

The unSelectable attribute sets whether the selection process can start in an element's content or not. 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.

>In Firefox, Google Chrome and Safari, the -moz-user-select and -webkit-user-select style properties are used for implementing similar functionality.

The difference between the unSelectable attribute and the -moz-user-select and -webkit-user-select style properties is that the -moz-user-select and -webkit-user-select style properties specify whether an element can be selected while the unSelectable attribute only specifies whether the selection process can start in an element's content or not. Another difference is that the unSelectable attribute is not inherited while the -moz-user-select and -webkit-user-select style properties are inherited. It means that the unSelectable attribute must be set on all non-selectable elements regardless of whether the unSelectable attribute is set on the parent element of a non-selectable element or not.


This usecase

The relevant HTML would have been helpful to construct a canonical answer. However if the element is a dynamic element or the website is Kendo UI based, then to click on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • Using WebDriverWait and xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath(&quot;//span[starts-with(., &#39;TrailVersion&#39;) and contains(., &#39;Testing_Demo&#39;)]&quot;))).click();
    
  • Using Actions and xpath:

    new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath(&quot;//span[starts-with(., &#39;TrailVersion&#39;) and contains(., &#39;Testing_Demo&#39;)]&quot;)))).click().build().perform();
    
  • Using JavascriptExecutor and xpath:

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

Reference

You can find a relevent detailed discussion in:

huangapple
  • 本文由 发表于 2020年7月27日 17:25:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/63112365.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定