![](/img/trans.png)
[英]Unable to click the 'button' in selenium webdriver (using Java)
[英]Button click in selenium webdriver - java
尝试单击Web应用程序中的按钮。 我正在用Chrome打开下面的页面,但是正在尝试单击页面内的按钮,但无法执行。
package example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Example {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver",
"E:/chromedriver_win32/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://localhost:4848/sense/app/C%3A%5CUsers%5Cpramod.STAR%5CDocuments%5CQlik%5CSense%5CApps%5Cdailyreportsample/sheet/PTdBnn/state/analysis");
driver.findElement(
By.cssSelector("div.qui-buttonset-left ng-scope button.qui-popover-button.qui-dropdown.ng-scope.ng-isolate-scope.qui-button"))
.click();
WebElement element = driver.findElement(By.name("a"));
element.submit();
driver.quit();
}
}
我用xpath尝试也没有得到。 当我单击按钮时,我的xpath帮助器将显示以下查询。
/ html [@ class ='touch-off'] / body [@ class ='qv-client qv-story-disabled qv-sheet-enabled qv-view-sheet'] / div [@ class ='qv-panel-包裹 '] /格[@ ID =' QV-工具栏容器 '] /格[@类=' NG-范围 '] /格[@类=' 魁工具栏 '] /格[@类=' 机更buttonset-left ng-scope'] / button [@ class ='qui-popover-button qui-dropdown ng-scope ng-isolate-scope qui-button'] [2]
HTML代码段:Button
<button class="qui-popover-button qui-dropdown ng-scope ng-isolate-scope qui-button" tid="2fedac" data-ng-disabled="quiModel.isDisabled()" data-ng-class="buttonClasses" data-icon="toolbar-menu" q-title-translation="Toolbar.Menu" data-qva-activate="onClick()" qui-model="globalMenuButton" ng-if="!isSmallDevice" title="Menu"></button>
尝试在页面加载后添加wait(Implicit / Explicit),您应该按如下所示修改CSS选择器:
driver.findElement(By.cssSelector("div[class^='qui-toolbar']>div>button")).click();
尝试以下XPATH定位器。
driver.findElement(By.xpath("//button[@class='qui-popover-button qui-dropdown ng-scope ng-isolate-scope qui-button']")).click();
要么
driver.findElement(By.xpath("//button[@title='Menu']")).click();
这对我有用。
WebElement menuButton = driver.findElement(By
.cssSelector("button.qui-popover-button:nth-child(2)"));
menuButton.click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.