我有一个未能识别不过,我能够识别并与上述线23和81以下的所有Web元素进行交互线23和81之间的任何网络元素硒一些网络驱动程序代码。
19 ….
20 <div id="main" class="well content" ui-view="content">
21 <iframe src="swagger-ui/index.html" frameborder="0" marginheight="0" marginwidth="0"
22 width="100%" height="900" scrolling="auto" target="_top" title="Swagger UI">
23 #document
24 <!doctype html>
25 <html>
26 <head>…</head>
27 <body class= “swagger-section” marginWidth= “0” marginheight= “0”>
<div class = “swagger-ui-wrap”>
<a id =”logo” href=http://swagger.io>swagger</a>
…
</div>
80 </body>
81 </iframe>
82 </div>
83 ….
我已经添加了以下Maven依赖我的POM:
<!-- https://mvnrepository.com/artifact/io.swagger/swagger-core -->
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-core</artifactId>
<version>1.5.21</version>
</dependency>
可能有人请让我知道如果有,我需要在我的POM包括或提供一些见解,以额外的依赖,为什么在下面的语句大小= 0?
size = driver.findElements(By.xpath("//*[@id='swagger-ui-container']")).size();
硒的webdriver不能识别线23和81的那些线之间的任何网络元件:
21 <iframe src="swagger-ui/index.html" frameborder="0" marginheight="0" marginwidth="0"
22 width="100%" height="900" scrolling="auto" target="_top" title="Swagger UI">
23 #document
24 <!doctype html>
25 <html>
26 <head>…</head>
27 <body class= “swagger-section” marginWidth= “0” marginheight= “0”>
<div class = “swagger-ui-wrap”>
<a id =”logo” href=http://swagger.io>swagger</a>
…
</div>
80 </body>
81 </iframe>
是一个<iframe>
内。
为了识别和你有一个<iframe>
标签内的所有WebElements互动:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe[title='Swagger UI'][src='swagger-ui/index.html']")));
my_size = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector("#swagger-ui-container"))).size();
XPath的:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@title='Swagger UI' and @src='swagger-ui/index.html']")));
my_size = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//*[@id='swagger-ui-container']"))).size();
在这里,你可以找到关于Ways to deal with #document under iframe相关讨论