[英]Not able to click Button(element) on Selenium webdriver
Not able to click Button(element) on Selenium webdriver. 无法在Selenium Webdriver上单击Button(元素)。 It's showing no such element exception. 它没有显示此类元素异常。
HTML: 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: 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();
The id might be dynamic, try to locate the button by partial id that contains datepicker
and title
该ID可能是动态的,请尝试按包含datepicker
和title
部分ID来定位按钮
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();
这应该工作:
driver.findElement(By.id("datepicker-354-7412-title")).click();
Have you tried putting your xpath in firepath and checking if its pointing to what you want? 您是否尝试过将xpath放在firepath中并检查其是否指向您想要的东西?
have you tried using 你尝试过使用
//strong[@class='ng-binding'] as your xpath? // strong [@ class ='ng-binding']作为您的xpath?
let know if this helps? 让我们知道这是否有帮助?
Find xpath using firefox addon firebug: - inspect element - right click on element and copy xpath 使用firefox插件firebug查找xpath:-检查元素-右键单击元素并复制xpath
Firebug's xpath generator is really good and the path generated generally works on other browsers. Firebug的xpath生成器非常好,生成的路径通常可在其他浏览器上使用。
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.