0
<td width="14%" height="90" valign="top" id="cell_saturday1" name="06/02/2018" onclick="onClick(this);">
<table width="100%" height="30" id="table_saturday1"></table>
</td>

Is there any way I can click anywhere on td in above code not containing table with the id table_saturday1?

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
fzn
  • 1
  • 1
  • 1

3 Answers3

1

You can use this Xpath to click on td which is clickable :

//td[@id='cell_saturday1' and @name='06/02/2018' and contains(@onclick,'onClick(this);')]
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
1

You can try with javascript executor as given below.

JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('cell_saturday1').click();");

or

WebElement ele = driver.findElement(By.id("cell_saturday1"));
jse.executeScript("arguments[0].click();",ele);

or Using action class

Actions builder = new Actions(driver);   
builder.moveToElement(ele, 0, 0).click().build().perform();
Murthi
  • 5,299
  • 1
  • 10
  • 15
  • I had a similar issue where the FirefoxDriver (Chrome and IE were fine) was not appearing to click on the cell. Using the Actions approach and specifying an X offset of 5 fixed the issue. I guess it was clicking on the border or off to the side of the cell for some reason. `Actions builder = new Actions(driver); builder.moveToElement(ele, 0, 5).click().build().perform();` – Andrew Brown Feb 27 '19 at 22:00
0

To click anywhere within the <td> except the childnode <table> with id as table_saturday1 you can use the following Locator Strategy Locator Strategy :

  • cssSelector:

    "td#cell_saturday1:not(#table_saturday1)"
    
  • xpath:

    "//td[@id='cell_saturday1' and not(@id='table_saturday1')]"
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352