0

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:&quot;j_idt67:j_idt68:j_idt69:j_idt229:pendingTable:dataTable:0:j_idt281&quot;,p:&quot;j_idt67&quot;,u:&quot;j_idt67&quot;,f:&quot;j_idt67&quot;});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

6
  • Does it perform the action when you click manually? If it "seems" to click it in the test, it means that your test is failing and you need to fix the page itself, not the test. Commented Apr 5, 2018 at 10:38
  • 2
    @KeyurPotdar Please take care while you edit or approve the edits. OP's initial HTML had 2 <span> tags but after 2 simultaneous edits only 1 <span> tag remains. OP may not receive any effective Answers. Reverting back to OP's initial version of the question. Commented Apr 5, 2018 at 10:58
  • 2
    @yarwest Please take care while you edit or approve the edits. OP's initial HTML had 2 <span> tags after 2 simultaneous edits only 1 <span> tag remains. OP may not receive any effective Answers. Reverting back to OP's initial version of the question. Commented Apr 5, 2018 at 10:58
  • 1
    @DebanjanB, thanks for noticing that and pinging me. I completely overlooked that. My bad. Commented Apr 5, 2018 at 10:59
  • 1
    @DebanjanB apologies, might have been my oversight Commented Apr 5, 2018 at 11:02

1 Answer 1

1

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();

Update A

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);

Update B

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();
Sign up to request clarification or add additional context in comments.

8 Comments

Hi Thank you , however I tried above it still does not work , it locates the element , however does not action , if you look at the HTML , there is a return false , could that not be causing an issue?
@SoopaStylin Checkout my answer update and let me know the result.
..Still no luck
JavascriptExecutor js = (JavascriptExecutor)chromeDriver; 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']")); js.executeScript("arguments[0].click();", elem);
@SoopaStylin Check my second answer update and let me know the result.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.