Reputation: 31
Very new to automation and have not had issues until now
I have a button that once clicked , a pop up button appears which one could click and it would perform a certain action.
I get to the second button and it seems to click it , however it does not perform the relevant action
My Code
//First Button//
WebElement AddUserSelect =
chromeDriver.findElementBy.id(
"j_idt67:j_idt68:j_idt69:j_idt229:pendingTable:dataTable:0:j_idt280_menuButton"));
AddUserSelect.click();
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Second Button//
WebElement AddUser =
chromeDriver.findElement(By.id(
"j_idt67:j_idt68:j_idt69:j_idt229:pendingTable:dataTable:0:j_idt281"));
AddUser.click();
Element on page when I inspect
<a
id="j_idt67:j_idt68:j_idt69:j_idt229:pendingTable:dataTable:0:j_idt281"
class="ui-menuitem-link ui-corner-all" href="#"
onclick="PrimeFaces.ab({s:"j_idt67:j_idt68:j_idt69:j_idt229:pendingTable:dataTable:0:j_idt281",p:"j_idt67",u:"j_idt67",f:"j_idt67"});return false;"
>
<span class="ui-menuitem-icon ui-icon ui-icon-extlink"></span>
<span class="ui-menuitem-text">
Add
</span>
</a>
Any Assistance would be appreciated..Thank you
Upvotes: 0
Views: 1023
Reputation: 193058
As per the HTML you have shared you target the second inner span tag and can use the following Locator Strategy to click on the intended element :
chromeDriver.findElement(By.xpath("//a[@class='ui-menuitem-link ui-corner-all' and starts-with(@id,'j_idt')]//span[@class='ui-menuitem-text']")).click();
As per your comment update as the previous line of code locates the element, however does not action as an alternative you can use the Javascript Click as follows :
WebElement elem = chromeDriver.findElement(By.xpath("//a[@class='ui-menuitem-link ui-corner-all' and starts-with(@id,'j_idt')]//span[@class='ui-menuitem-text']"));
driver.executeScript("arguments[0].click();", elem);
Induce a waiter through WebDriverWait as follows :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='ui-menuitem-link ui-corner-all' and starts-with(@id,'j_idt')]//span[@class='ui-menuitem-text']"))).click();
Upvotes: 1