Selenium can not find by id

2

I'm running a test with testNG along with Selenium

org.openqa.selenium.By

Test, do this search:

driver.findElement(By.id("idRoleCheck:0")).click();

It gives the following error:

  

org.openqa.selenium.ElementNotVisibleException: element not visible

Analyzed with the Chrome development tool, I have the Id, I can see it, but I think it's a problem with this ":" character, but I do not know, I already tried several searches here and others places and nothing.

I'm using the driver:

org.openqa.selenium.chrome.ChromeDriver

Has anyone ever been through this?

HTML generated in browser:

<div class="ui-helper-hidden-accessible">
    <input id="idRoleCheck:0" name="idRoleCheck" value="value"
     onchange="PrimeFaces.ab({s:&quot;idRoleCheck&quot;,e:&quot;change&quot;,p:&quot;idRoleCheck&quot;,u:&quot;idRoleCheck&quot;});" 
    type="checkbox">
</div>

None of the answers so far resolved. However we evolved we were able to pass the test.

driver.findElement(By.xpath("//table[@id='idRoleCheck']/tbody/tr/td/div/div[2]/span")).click();

The problem in reading the id of the questioned form continues, perhaps it is missing some dependency that is generating the problem, because the log never comes with too much information. p>

Using:

How the problem was found

Using:

  • Selenium IDE (that firefox plugin to write test data)
  • Exported to type (TestNG / Java / WebDriver)
  • It generates two lines, the first one that gives the error (idRoleCheck: 0)
  • The second reading by By.xpath (...
asked by anonymous 23.09.2016 / 16:27

4 answers

1

I had a similar problem and was able to resolve with the following function

Try as follows:

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript( "setTimeout(function(){ document.getElementById('idRoleCheck:0').value = 'value'; }, 1000)");

If somewhere has a data-bind referenced for this id, use it as follows:

js.executeScript(
            "setTimeout(function(){ model."o que tiver dentro do seudata-bin"('o valor que você quer selecionar'); document.getElementById('idRoleCheck:0').value = 'value'; }, 1000)");
    
23.09.2016 / 20:50
0

Try to put two backslashes before:, like this:

driver.findElement(By.id("idRoleCheck\:0")).click();
    
23.09.2016 / 21:10
0

I've had many problems of this kind, especially with IE. You can try to find the element by the attribute.

By.cssSelector("input[id=idRoleCheck:0]");
    
06.10.2016 / 14:57
0

Because you do not search for all elements of type checkbox and then click on the element you want, it's always the easiest way.

Type like this:

List<WebElement> checkboxes = 
driver.findElements(By.cssSelector("input[type*=\"checkbox\"]"));
checkboxes.get(0).click();
    
24.11.2016 / 23:11