0

What I am trying:

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

Option 1:

element.click();

Option 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." }
       

Option 3:

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

I would like to highlight that span tag contains attribute <span unselectable = "on"> 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?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 'unselectable' is pretty much clear. You have to get rid of the attribute (or change it's value to 'off') using javascript. See https://stackoverflow.com/questions/38751384/clicking-on-a-field-name-whose-unselectable-is-on-using-selenium – pburgr Jul 27 '20 at 12:27

1 Answers1

0

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("//span[starts-with(., 'TrailVersion') and contains(., 'Testing_Demo')]"))).click();
    
  • Using Actions and 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();
    
  • Using JavascriptExecutor and xpath:

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

Reference

You can find a relevent detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352