-1

I want to click "Action" button and select the option "Update Reference data".
Actions button enter image description here

Here is my code

 Thread.sleep(30000);// To load the page
 driver.findElement(By.xpath("//*[@id=\"spend_mgmt_actions_menu\"]")).click();
 Thread.sleep(2000);
 driver.findElement(By.xpath("//*[id=\"upgradeRefData_button\"]")).click();

I also tried this, but got the same exception

WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id=\"spend_mgmt_actions_button\"]")));
driver.findElement(By.className("button show-right-icon f-dropdown-facade actions-list-button plan-action-button")).click();
Thread.sleep(20000);

But when I run the code it gives:

No Such Element Exception unable to locate.....

Below is the HTML code copied from browser by selecting the element.

<button id="spend_mgmt_actions_button"
class="button show-right-icon f-dropdown-facade actions-list-button plan-action-button"
aria-hidden="false" aria-haspopup="true" data-dropdown="spend_mgmt_actions_menu" tabindex="0">
<span>Actions</span><span class="icon icon-right fa fa-caret-down"></span></button>


 <button id="upgradeRefData_button" class="list-item dd-item" aria-disabled="false"
 data-dropdown-item="" role="menuitem" tabindex="0" title=""><span>Update Reference Data</span>
 </button>
Guy
  • 46,488
  • 10
  • 44
  • 88
Gaurav Bahadur
  • 189
  • 2
  • 14

1 Answers1

0

You were close. To click() on the element with text as Actions and then to click() the element with text as Update Reference Data you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.button.show-right-icon.f-dropdown-facade.actions-list-button.plan-action-button#spend_mgmt_actions_button>span"))).click();
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.list-item dd-item#upgradeRefData_button>span"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='button show-right-icon f-dropdown-facade actions-list-button plan-action-button' and @id='spend_mgmt_actions_button']/span[text()='Actions']"))).click();
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='list-item.dd-item' and @id='upgradeRefData_button']/span[text()='Update Reference Data']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I tried both the methods but none of them worked. I'm getting Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.cssSelector: button.button.show-right-icon.f-dropdown-facade.actions-list-button.plan-action-button#spend_mgmt_actions_button>span (tried for 20 second(s) with 500 milliseconds interval) which is caused by Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector"... – Gaurav Bahadur Dec 16 '19 at 07:07
  • @GauravBahadur _TimeoutException_ is the outcome of **failed** _ExpectedConditions_. Debug your code through `findElement()` inconjunction with `Thread.sleep()`. If you are able to locate the element, update the question with the observations. – undetected Selenium Dec 16 '19 at 07:37