Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
如何获取存储在<;中的链接url(href);李>;在WebDriver中使用java_Java_Selenium_Selenium Webdriver - Fatal编程技术网

如何获取存储在<;中的链接url(href);李>;在WebDriver中使用java

如何获取存储在<;中的链接url(href);李>;在WebDriver中使用java,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我有一个像这样的html源代码 问题出在.cssSelector(“子菜单项”)中,应该是 By.cssSelector(“.submenuitem”)或By.className(“submenuitem”) 另一种可能是 List<WebElement> links = driver.findElements(By.cssSelector("[href*='/mysite']")); List links=driver.findElements(By.cssSel

我有一个像这样的html源代码


问题出在.cssSelector(“子菜单项”)中,应该是
By.cssSelector(“.submenuitem”)
By.className(“submenuitem”)

另一种可能是

List<WebElement> links = driver.findElements(By.cssSelector("[href*='/mysite']"));
List links=driver.findElements(By.cssSelector(“[href*='/mysite']”);

这将为您提供包含
“/mysite”

的所有
href
,是的,您是对的,我应该使用.cssSelector(.subnumitem”)的
来删除项目,但是
链接.get(i).getAttribute(“href”)
仍然显示为空,这是因为
href
中,不是
li
所以有没有办法只在`
  • `元素下面获取href:(我是web驱动程序新手,没有找到解决方案。请尝试driver.findelelements(By.cssSelector(“.subnumitem>”);这应该会为您提供所有
    a
    元素。