Java AngularJs页面问题,选择一个元素并单击它

Java AngularJs页面问题,选择一个元素并单击它,java,angularjs,selenium,Java,Angularjs,Selenium,我在选择并单击某个元素时遇到问题,因此此处出现的下拉列表是我现在尝试的uptill:- String csspath="html body.ng-scope f:查看表单#wdesk.ng-pristine.ng-valid div.container div.ng-scope md content.md padding.#md md-tabs.ng-isolation-scope.md-dynamic-height md tabs content wrapper.#md md-tab con

我在选择并单击某个元素时遇到问题,因此此处出现的下拉列表是我现在尝试的uptill:-

String csspath="html body.ng-scope f:查看表单#wdesk.ng-pristine.ng-valid div.container div.ng-scope md content.md padding.#md md-tabs.ng-isolation-scope.md-dynamic-height md tabs content wrapper.#md md-tab content-7.#md.ng-scope.md-md-md-active-no-scroll div.ng-scope-scope.ng-scope.ng-scope.ng-scope.ng-scope ng-scope ng-include ng-scope div-分类accordion-group.ng-isolate-scope分类accordion-heading a.accordion-toggle.ng-binding span.ng-scope b.ng-binding”;
String uxpath=“//html//body//f:view//form//div//div[2]//md content//md tabs//md tabs content wrapper//md tab content[1]//div//ng include//div accordio//div//div div[1]//a”;
字符串xpath2=“/html/body/pre/span[202]/a”;
xpath=“/html/body/f:view/form/div/div[2]/md content/md tabs/md tabs content wrapper/md tab content[1]/div/ng include/div/accordion/div/div[1]/div[1]/a/span/b”;
试一试{
元素=wait.until(预期条件。元素的可见性(由.cssSelector(csspath))定位);
定位器=通过.css选择器(csspath);
driver.findElement(locator).click();
}捕获(例外e){
系统输出打印(“非foune csspath”);
}
试一试{
element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath));
locator=By.xpath(xpath);
driver.findElement(locator).click();
}捕获(例外e){
System.out.println(“非foune xpath”);
}
试一试{
element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(uxpath));
locator=By.xpath(uxpath);
driver.findElement(locator).click();
}捕获(例外e){
System.out.println(“非foune uxpath”);
}
试一试{
element=wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath2));
locator=By.xpath(xpath2);
driver.findElement(locator).click();
}捕获(例外e){
System.out.println(“非foune xpath2”);
}
第一个问题(正如评论中已经指出的)是您正在使用的绝对选择器。例如,尝试重构您的xpath选择器,并使其可用

下一个问题与

AngularJs页面

本身。让我们来看一下,Angular的测试框架是基于WebDriverJ构建的,它提供了额外的WebDriver类功能来测试基于Angular的网站。简单来说,您的代码需要额外的功能,可以知道Angular元素何时可用于交互

下面是一些对Java(和Python)最有用的量角器函数:


你能用一些更相关的HTML标签正确粘贴问题中的HTML DOM吗?真的很抱歉,我不能,因为我没有足够的声誉yetokay,如果你使用的url是公开的,你能和我共享这个url吗?你所有的xpath都很长,谷歌关于如何找到好的xpath和css。它应该是快照,应该可以要唯一地查找元素,请使用和之类的工具检查XPath是否有效。我使用的url不是公共的