Java 无法通过带::before的div内的xpath获取元素
我需要使用web驱动程序对象获取web元素列表Java 无法通过带::before的div内的xpath获取元素,java,selenium,xpath,web-scraping,pseudo-element,Java,Selenium,Xpath,Web Scraping,Pseudo Element,我需要使用web驱动程序对象获取web元素列表 findElements(By.xpath(“”); 我使用xpath作为/*[@class=\“providers list clearfix\”]获取列表。但是,每当我尝试获取其中的元素时,都会出现错误 ::之前 .. 这个xpath给了我一个错误: //[@class=\“data container\”]”因为没有这样的元素:无法找到元素:{“method”:“xpath”,“selector”:“/[@class=“data cont
findElements(By.xpath(“”);
我使用xpath作为/*[@class=\“providers list clearfix\”]
获取列表。但是,每当我尝试获取其中的元素时,都会出现错误
::之前
..
这个xpath给了我一个错误:
//[@class=\“data container\”]”因为没有这样的元素:无法找到元素:{“method”:“xpath”,“selector”:“/[@class=“data container”]”
请使用此X路径-/*[contains(@class,'clearfix')]您是否试图从查找删除的对象进行访问?理想情况下,它是这样工作的:
List <WebElement> myList = driver.findElements(By.xpath("//*[@class=\"providers-list clearfix\"]"));
for(WebElement eachList:myList)
{
System.out.println(eachList.findElement(By.xpath("div[1]")).getText());
}
List myList=driver.findElements(By.xpath(“/*[@class=\”提供者列表clearfix\”);
for(WebElement每个列表:myList)
{
System.out.println(eachList.findElement(By.xpath(“div[1]”).getText());
}
例如,元素的存在意味着该元素为:
- 样式或
- 在某些内容之前插入
:css选择器
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.providers-list.clearfix div.data-container")));
:xpath
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='providers-list clearfix']//div[@class='data-container']")));