0

i have the follow problem:

I'm working with a table, and this table shows information. this information is clickable in any place of the row (can be clickable in the first td, or the second td, etc). The thing is when i try to locate the path, i receive the follow error:

Unable to find element with xpath == //*[@id='id9e']/td[2]/div

the html code is:

<table class="table table-bordered table-striped dataview" id="id102">
<tbody>
    <tr id="id9e">
        <td>
            <div>300374              </div>
        </td>
        <td>
            <div>0300374034</div>
        </td>

Java Code is:

Actions dclick = new Actions(driver);
WebElement element = driver.findElement(By.xpath("//*[@id='id9e']/td[2]/div"));
dclick.doubleClick(element).perform();

Im trying to click the second td. I get the xpath directly from the DOM

could you Help me with this?

Thanks guys

  • Are you sure, the table is loaded by the time the line of code executed?check if the table is wrapped in the iframe. – supputuri Apr 14 '20 at 01:52
  • i've tried this: new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//tr[@id='id9e']/td[2]/div"))).click(); and received this: Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: //tr[@id='id9e']/td[2]/div (tried for 20 second(s) with 500 milliseconds interval) – Don Gonzalo Cortez Mayer Apr 14 '20 at 13:52
  • Seems to be the table is wrapped in iframe. Check if the element is present in the iframe using `//*[@id='id9e']/ancestor::html` in the chrome devtools as shown here[here](https://stackoverflow.com/questions/55870609/is-there-a-way-to-learn-xpath-without-using-firebug-or-xpath-as-firefox-is-not-s/55870909#55870909). If it's not pointing to the root html then check the parent of the html in the devtools. – supputuri Apr 14 '20 at 14:00

1 Answers1

0

One of the reason I can think is element is yet to load so put some wait in your code.

wait.until()

this will solve your problem.

zealous
  • 7,336
  • 4
  • 16
  • 36