我需要使用selenium计算屏幕中可见图像的数量
我将xpath
转为两个:
Actual_xpath=//div[@id='ShowBox']/descendant::div[contains(@class, 'ShowColumn ')]/descendant::a[@class='logo']
分成两部分:
homePageShowLogoPartOne_XPATH=//div[@id='ShowBox']/descendant::div[
homePageShowLogoPartTwo_XPATH=]/descendant::div[contains(@class,'ShowColumn ')]/descendant::a[@class='logo']
运行脚本时: -
int showCount = driver.findElements(
By.xpath(ObjRepoProp.getProperty("homePageShowLogoImage_XPATH"))).size();
//System.out.println("hai");
System.out.println("hai123");
int j = 0;
System.out.println("hai456");
for (int i = 1; i <= showCount; i++) {
// Getting Shows title from My Shows page
System.out.println("hai789");
log.info(driver.findElement(By.xpath(ObjRepoProp.getProperty("homePageShowLogoPartOne_XPATH"+ i + driver.findElement(By.xpath(ObjRepoProp.getProperty("homePageShowLogoPartTwo_XPATH")))))).isDisplayed());
System.out.println("hai1011");
j = j + 1;
}
log.info(j + " shows are present in GET TO KNOW THE SHOW section (Count of only shows which are displaying on screen).\n");
运行脚本获取'homePageShowLogoPartTwo_XPATH'为
无效的选择器:无法找到带有xpath的元素 表达式] / descendant :: div [contains(@ class,'ShowColumn ')] /后代::一个[@类=' 标志']
提前致谢。
答案 0 :(得分:0)
该异常是由此段代码中的错误引起的:
log.info(driver.findElement(By.xpath(ObjRepoProp.getProperty("homePageShowLogoPartOne_XPATH"+ i + driver.findElement(By.xpath(ObjRepoProp.getProperty("homePageShowLogoPartTwo_XPATH")))))).isDisplayed());
在By.xpath部分中而不是使用
ObjRepoProp.getProperty("homePageShowLogoPartTwo_XPATH")
你用过
driver.findElement(By.xpath(ObjRepoProp.getProperty("homePageShowLogoPartTwo_XPATH"))
这就是你获得例外的原因。 将其更改为获取属性,它将按预期工作。
log.info(driver.findElement(By.xpath(ObjRepoProp.getProperty("homePageShowLogoPartOne_XPATH") + i + ObjRepoProp.getProperty("homePageShowLogoPartTwo_XPATH"))).isDisplayed());