0

I am trying to click on a field which is exactly not clickable. I am attaching the screenshot of the screen.

The Html code behind the page is:

<td class="x-grid3-col x-grid3-cell x-grid3-td-TRAVNAME " style="width:  234px;" tabindex="0">
<div class="x-grid3-cell-inner x-grid3-col-TRAVNAME"   unselectable="on">ARUNACHALAM/SHAN</div>
</td>

The code that I have written is in C# which is as follows:

Thread.Sleep(1000);
Driver.Instance.FindElement(By.XPath("//*[@id='ext - gen13']/div/table/tbody/tr/td[3]/div")).Click();

Its throwing exception saying it is unable to find the field.

Can someone please help?enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Have you checked to ensure your xpath is valid/correct? – Josh Aug 03 '16 at 19:01
  • It is correct, because I have copied directly from the Inspect –  Aug 03 '16 at 19:03
  • OK, maybe instead of using `Thread.Sleep()` you could use a `WebDriverWait` to wait until the element is definitely visible. – Josh Aug 03 '16 at 19:04
  • I have tried that as well, the problem I think is not with the Thread.Sleep or WebDriverWait, it is with the field which has unselectable on, in that way it is unable to find the field name. I have got an answer in this link http://sqa.stackexchange.com/questions/8371/selenium-element-not-selectable-for-a-kendo-ui-element but I am not exactly sure as to how to use it. :( –  Aug 03 '16 at 19:08

2 Answers2

1

Try using WebDriverWait as below :-

var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(20));
var el =    wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("td.grid3-td-TRAVNAME div.x-grid3-col-TRAVNAME")));
el.Click();

Edited : If unfortunately it's not clickable due to unselectable="on", remove this attribute property before clicking using IJavascriptExecutor as below :-

var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(20));
var el =    wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("td.grid3-td-TRAVNAME div.x-grid3-col-TRAVNAME")));

IJavaScriptExecutor js = Driver.Instance as IJavaScriptExecutor;
el = (IWebElement)js.ExecuteScript("arguments[0].removeAttribute('unselectable'); return arguments[0];", el);
el.Click();

Edited :- cssSelector does not work here try using By.Xpath() as below :-

var el =    wait.Until(ExpectedConditions.ElementIsVisible(By.Xpath(".//div[contains(text(), 'ARUNACHALAM/SHAN')]")));
Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
  • Hi Saurabh, thanks for the answer, but I have already used it, the problem is the element is not clickable here, if you see the html code unselectable="on" here. –  Aug 04 '16 at 02:28
  • @Adrija then need to remove this attribute before click..:) – Saurabh Gaur Aug 04 '16 at 02:50
  • I tried with your edited code as well, it didn't work..threw me an exception saying timed out after 20secs, I also tried with Thread Sleep(1000), it gave me the exception saying unable to locate the element :( –  Aug 04 '16 at 15:06
  • @Adrija Once try with `ExpectedConditions.ElementIsExists` instead of `ExpectedConditions.ElementIsVisible` and let me know...:) – Saurabh Gaur Aug 04 '16 at 15:09
  • @Adrija and make sure this element is not inside any frame or iframe...:) – Saurabh Gaur Aug 04 '16 at 15:10
  • It says ExpectedConditions is having no defination for ElementIsExists, do we require separate class or namespace for it? –  Aug 04 '16 at 15:15
  • @Adrija sorry it's `ExpectedConditions.ElementExists`..just typo mistake..try this – Saurabh Gaur Aug 04 '16 at 15:17
  • Its still showing the same error Timed out after 20 secs :'( –  Aug 04 '16 at 15:20
  • I dont think so its in a separate frame, but its in a separate form. –  Aug 04 '16 at 15:23
  • @Adrija and what about frame?? Did you look for frame or iframe?? – Saurabh Gaur Aug 04 '16 at 15:23
  • Ok once try using `By.Xpath(".//div[contains(text(), 'ARUNACHALAM/SHAN')]")` and let me know...:) – Saurabh Gaur Aug 04 '16 at 15:25
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.

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 CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("td.x-grid3-td-TRAVNAME > div.x-grid3-col-TRAVNAME"))).Click();
    
  • Using WebDriverWait and XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//td[@class='x-grid3-col x-grid3-cell x-grid3-td-TRAVNAME ']/div[text()='ARUNACHALAM/SHAN']"))).Click();
    
  • Using IJavaScriptExecutor and CssSelector:

    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CssSelector, "td.x-grid3-td-TRAVNAME > div.x-grid3-col-TRAVNAME"))));
    
  • Using IJavaScriptExecutor and CssSelector:

    ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[@class='x-grid3-col x-grid3-cell x-grid3-td-TRAVNAME ']/div[text()='ARUNACHALAM/SHAN']"))));
    

Reference

You can find a relevent detailed discussion in:

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