Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium IDE定位器不';t在Selenium 3.3.1 Java中工作_Java_Css_Selenium_Ide_Fluentlenium - Fatal编程技术网

Selenium IDE定位器不';t在Selenium 3.3.1 Java中工作

Selenium IDE定位器不';t在Selenium 3.3.1 Java中工作,java,css,selenium,ide,fluentlenium,Java,Css,Selenium,Ide,Fluentlenium,我有一个网页,其中包含两个具有相同类名但具有不同div类的链接。第一个是不可见的(在下拉菜单中),另一个我想要的是可见的。 所以,我试图定位可见元素 他的HTML: <div class="mainActionPanel"> <a css="create"></a> </div> 该链接有一个动态ID。当我使用该ID进行XPath搜索时,我正确地找到了元素,但它被弃用,因为按钮在每个页面上没有相同的ID 我试图用Selenium I

我有一个网页,其中包含两个具有相同类名但具有不同div类的链接。第一个是不可见的(在下拉菜单中),另一个我想要的是可见的。 所以,我试图定位可见元素

他的HTML:

 <div class="mainActionPanel">
   <a css="create"></a>
 </div>

该链接有一个动态ID。当我使用该ID进行XPath搜索时,我正确地找到了元素,但它被弃用,因为按钮在每个页面上没有相同的ID

我试图用Selenium IDE定位元素,以下定位器工作:
css=div.mainActionPanel>a.create

问题在于我上面显示的定位器。 当我尝试查找元素时,总是出现以下异常:

NoSuchElementException:Element By.css选择器:css=div.mainActionPanel>a.create(first)(LazyElement)不存在

他没有找到它。我尝试了几种语法,比如FluentLenium文档中的一个示例(
$(
input[data custom=selenium]”
),但都不起作用

此外,
el(“.create”).click()
正在抛出ElementNotVisibleException,因为他选择了下拉链接


我怎样才能找到合适的元素呢?

也许这会对您有所帮助

 // this will provide you list of web elements based on class name
 List<WebElement> webElements = driver.findElements(By.className("mainActionPanel"));
完整代码如下:

  List<WebElement> webElements = driver.findElements(By.className("mainActionPanel"));

  WebElement tempElement = null;
  for (WebElement element : webElements) {

            if (element.getAttribute("css").equals("create")) {
                tempElement = element;
            }
  }


  //then you can perform that you want
  tempElement.click();
List webElements=driver.findElements(By.className(“mainActionPanel”);
WebElement tempElement=null;
for(WebElement:webElements){
if(element.getAttribute(“css”).equals(“创建”)){
tempElement=元素;
}
}
//然后你可以做你想做的事
tempElement.click();

使用以下命令将css搜索更改为xpath:

xpath = (//a[contains(@href, '#')])[5]
因为它是第四个带有href属性的“a”元素,其中包含文本“#”

看看这个:

尝试使用以下方法:

 WebElement elem = driver.findElement(By.cssSelector("div.mainActionPanel > a"));
 WebDriverWait wait= new WebDriverWait(driver, 20);

 wait.until(ExpectedConditions.visibilityOf(elem));

 elem.click();

不起作用,web元素列表为null=>NullPointerException您是否尝试过这种方法,在找到元素之前,请为至少4-5秒的WebElement WebElement=driver.findElement(By.cssName(“create”);此处不将类名指定为“.create”if条件似乎永远不会为true,因此tempElement保持为null并引发异常。if条件仅当且仅当元素在列表中时才会执行,否则它将不会执行。列表中有3个元素,我在调试模式下运行它,if条件有问题,因为它会引发null指针。
 WebElement elem = driver.findElement(By.cssSelector("div.mainActionPanel > a"));
 WebDriverWait wait= new WebDriverWait(driver, 20);

 wait.until(ExpectedConditions.visibilityOf(elem));

 elem.click();