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
使用java中的firefox webdriver从当前节点获取Xpath_Java_Selenium_Xpath_Selenium Webdriver - Fatal编程技术网

使用java中的firefox webdriver从当前节点获取Xpath

使用java中的firefox webdriver从当前节点获取Xpath,java,selenium,xpath,selenium-webdriver,Java,Selenium,Xpath,Selenium Webdriver,因此,在使用findElement(By.xpath(“…”) 首先,我要定位一个ul元素,它包含大约20个li子元素。 通过在每个子级上使用then,我使用以下命令定位信息的内部xpath: List<WebElement> addrBookNames = driver.findElements(By.xpath("//ul[@class='displayAddressUL']")); for(WebElement addr : addrBookNames) { Strin

因此,在使用
findElement(By.xpath(“…”)

首先,我要定位一个
ul
元素,它包含大约20个
li
子元素。 通过在每个子级上使用then,我使用以下命令定位信息的内部
xpath

List<WebElement> addrBookNames = driver.findElements(By.xpath("//ul[@class='displayAddressUL']"));
for(WebElement addr : addrBookNames)
{
    String fullName = addr.findElement(By.xpath("li[@class='AddressFullName']/b")).getText();
    String addressLine = addr.findElement(By.xpath("li[@class='AddressAddressLine']")).getText();
    String city = addr.findElement(By.xpath("li[@class='AddressCity']")).getText();
    String county = addr.findElement(By.xpath("li[@class='country']")).getText();
    String phoneNumber = addr.findElement(By.xpath("li[@class='phone']")).getText();

}
前后

我从所选节点提取内部XPath的方式是否有任何问题?

1)我将尝试作为可选的CSS选择器方法,并创建5个WebElement列表(已在搜索字段的拆分表示中):

1) 我将尝试作为CSS选择器的替代方法,创建5个WebElement列表(已在搜索字段的拆分表示中):

1) 我将尝试作为CSS选择器的替代方法,创建5个WebElement列表(已在搜索字段的拆分表示中):

1) 我将尝试作为CSS选择器的替代方法,创建5个WebElement列表(已在搜索字段的拆分表示中):


我认为你们做的是正确的。需要这么长时间吗?时间取决于路线,需要多少元素才能找到具体的路线。所以你的计算时间看起来很合理。webdriver没有每个元素的哈希数据结构?那个么每次搜索应该是O(1)?我认为你们做的是正确的。应该花那个么长的时间吗?时间取决于路由,它需要路由多少元素才能找到特定的。所以你的计算时间看起来很合理。webdriver没有每个元素的哈希数据结构?那个么每次搜索应该是O(1)?我认为你们做的是正确的。应该花那个么长的时间吗?时间取决于路由,它需要路由多少元素才能找到特定的。所以你的计算时间看起来很合理。webdriver没有每个元素的哈希数据结构?那个么每次搜索应该是O(1)?我认为你们做的是正确的。应该花那个么长的时间吗?时间取决于路由,它需要路由多少元素才能找到特定的。所以你的计算时间看起来很合理。webdriver没有每个元素的哈希数据结构?那么每次搜索哪个应该是O(1)?
double stime = System.currentTimeMillis();
double TotalTime = System.currentTimeMillis() - stime; 
List<WebElement> fullNames = driver.findELements(By.cssSelector("ul.displayAddressUL li.AddressFullName>b"));
List<WebElement> addressLines= driver.findELements(By.cssSelector("ul.displayAddressUL li.AddressAddressLine"));
List<WebElement> cities= driver.findELements(By.cssSelector("ul.displayAddressUL li.AddressCity"));
List<WebElement> countries=driver.findELements(By.cssSelector("ul.displayAddressUL li.country"));
List<WebElement> phoneNums=driver.findELements(By.cssSelector("ul.displayAddressUL li.phone"));

for (int i=0;i<fullNames.size(); i++){
String fullName= fullNames.get(i).getText();
String addressLine =addressLines.get(i).getText();
String city = cities.get(i).getText();
String county = countries.get(i).getText();
String phoneNumber = phoneNums.get(i).getText();
}
 String elem_css_selector="blablabla...";
 JavascriptExecutor js = (JavascriptExecutor) driver;
        StringBuilder stringBuilder = new StringBuilder();

stringBuilder.append("var x = $(\""+elem_css_selector+"\");");
        stringBuilder.append("return x.text().toString();")       ;


       String resultingText= (String) js.executeScript(stringBuilder.toString());
       Assert.assertTrue(resultingText.trim().equals("Expected Text")   );