0

enter image description hereNot able to click Button(element) on Selenium webdriver. It's showing no such element exception.

HTML:

<button id="datepicker-354-7412-title" class="btn btn-default btn-sm uib-title" tabindex="-1" ng-disabled="datepickerMode === maxMode" ng-click="toggleMode()" type="button" aria-atomic="true" aria-live="assertive" role="heading">
    <strong class="ng-binding">August 2016</strong>
</button>

Java:

driver.findElement(By.xpath("//*[@id='flip-card']/div[2]/div/div[2]/div[2]/div[1]/div/div[2]/i")).click();
driver.manage().timeouts().implicitlyWait(05, TimeUnit.SECONDS);
//driver.findElement(By.xpath("//ul[@class='uib-datepicker-popup dropdown-menu ng-scope']/li/div/table/thead/tr/th/button[@id='datepicker-758-2620-title']/strong")).click();
//driver.findElement(By.xpath(".//*[@id='datepicker-961-3767-title']")).click();
//WebElement mm=driver.findElement(By.id("datepicker-1164-5186-title"));
//mm.click();
/*WebElement element=driver.findElement(By.xpath("//*[@id='datepicker-354-7412-title']"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click()", element); */
driver.findElement(By.xpath("//button[@id='datepicker-354-7412-title']/strong")).click();
10
  • <button id="datepicker-354-7412-title" class="btn btn-default btn-sm uib-title" tabindex="-1" ng-disabled="datepickerMode === maxMode" ng-click="toggleMode()" type="button" aria-atomic="true" aria-live="assertive" role="heading"> <strong class="ng-binding">August 2016</strong> </button> Commented Aug 29, 2016 at 10:49
  • show your click Button code. Commented Aug 29, 2016 at 10:53
  • Please add the html and your Java code to the question. Commented Aug 29, 2016 at 10:53
  • <button id="datepicker-354-7412-title" class="btn btn-default btn-sm uib-title" tabindex="-1" ng-disabled="datepickerMode === maxMode" ng-click="toggleMode()" type="button" aria-atomic="true" aria-live="assertive" role="heading"> <strong class="ng-binding">August 2016</strong> </button> @Guy Commented Aug 29, 2016 at 11:02
  • could you show your code of clicking button? Commented Aug 29, 2016 at 11:03

4 Answers 4

1

The id might be dynamic, try to locate the button by partial id that contains datepicker and title

driver.findElement(By.cssSelector("[id*='datepicker'][id*='title']")).click();

You can also use explicit wait to make sure the button exist/visible before clicking on it

WebDriverWait wait = new WebDriverWait(driver, 10);

// visible
WebElement button = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("[id*='datepicker'][id*='title']")));
button.click();

// or exist
WebElement button = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("[id*='datepicker'][id*='title']")));
button.click();
Sign up to request clarification or add additional context in comments.

2 Comments

@boopathi Check again the html for <frame> or <iframe> tags. This is the only other explanation.
0

This should work:

driver.findElement(By.id("datepicker-354-7412-title")).click();

Comments

0

Have you tried putting your xpath in firepath and checking if its pointing to what you want?

have you tried using

//strong[@class='ng-binding'] as your xpath?

let know if this helps?

1 Comment

its working with this code driver.findElement(By.cssSelector("[id*='datepicker'][id*='title']")).click();
0

Find xpath using firefox addon firebug: - inspect element - right click on element and copy xpath

Firebug's xpath generator is really good and the path generated generally works on other browsers.

Hope that helps.

Comments

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.