- Wait.html<wbr><wbr></wbr></wbr>
- <wbr><wbr></wbr></wbr>
- <html><wbr><wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong><</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>head</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong><</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>title</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span>Set<wbr>Timeout<span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong></</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>title</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong><</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>style</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>.red_box<wbr>{background-color:<wbr>red;<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:red">width</span><wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">20</span>%;<wbr>height:<wbr>100px;<wbr>border:<wbr>none;}<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong></</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>style</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong><</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>script</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>function<wbr>show_div(){<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>setTimeout("create_div()",<wbr>5000);<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>function<wbr>create_div(){<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:red">d</span><wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">document</span>.createElement_x_x('div');<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:red">d.className</span><wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"red_box"</span>;<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>document.body.a(d);<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong></</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>script</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong></</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>head</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong><</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>body</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong><</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>button</strong></span><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:red">id</span><wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"b"</span><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:red">onclick</span><wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"show_div()"</span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span>click<span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong></</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>button</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong></</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>body</strong></span><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,102,153)"><strong>></strong></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- </html><wbr><wbr></wbr></wbr>
<wbr></wbr>
下面的代码实现了高亮动态生成的div块的功能:
<wbr></wbr>
Java代码<wbr>(){ @Override public WebElement apply(WebDriver d) { return d.findElement(By.id("b")); }}).click(); WebElement element = dr.findElement(By.cssSelector(".red_box")); ((JavascriptExecutor)dr).executeScript("arguments[0].style.border = \"5px solid yellow\"",element); } }" quality="high" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"><wbr><a href="http://jarvi.iteye.com/blog/1453662" title="收藏这段代码" style="text-decoration:none; color:rgb(62,115,160)"><img src="http://jarvi.iteye.com/images/icon_star.png" alt="收藏代码" title="[WebDriver]等待页面加载,(转载出自jarvi)" style="margin:0px; padding:0px; border:0px; list-style:none"></a></wbr></wbr>
- import<wbr>org.openqa.selenium.By;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.JavascriptExecutor;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.WebDriver;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.WebElement;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.firefox.FirefoxDriver;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.support.ui.ExpectedCondition;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.support.ui.WebDriverWait;<wbr><wbr></wbr></wbr></wbr>
- <wbr><wbr></wbr></wbr>
- <wbr><wbr></wbr></wbr>
- public<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>class</strong></span><wbr>WaitForSomthing<wbr>{<wbr><wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>public</strong></span><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>static</strong></span><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>void</strong></span><wbr>main(String[]<wbr>args)<wbr>{<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,130,0)">//<wbr>TODO<wbr>Auto-generated<wbr>method<wbr>stub</wbr></wbr></wbr></wbr></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>System.setProperty(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"webdriver.firefox.bin"</span>,<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"D:\\Program<wbr>Files\\Mozilla<wbr>Firefox\\firefox.exe"</wbr></wbr></span>);<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>WebDriver<wbr>dr<wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>new</strong></span><wbr>FirefoxDriver();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>String<wbr>url<wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"file:///C:/Documents<wbr>and<wbr>Settings/gongjf/桌面/selenium_test/Wait.html"</wbr></wbr></span>;//<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"/Your/Path/to/Wait.html"</span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>dr.get(url);<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>WebDriverWait<wbr>wait<wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>new</strong></span><wbr>WebDriverWait(dr,<span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(192,0,0)">10</span>);<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>wait.until(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>new</strong></span><wbr>ExpectedCondition<WebElement>(){<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(100,100,100)">@Override</span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>public</strong></span><wbr>WebElement<wbr>apply(WebDriver<wbr>d)<wbr>{<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>return</strong></span><wbr>d.findElement(By.id(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"b"</span>));<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}}).click();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>WebElement<wbr>element<wbr>=<wbr>dr.findElement(By.cssSelector(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">".red_box"</span>));<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>((JavascriptExecutor)dr).executeScript(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"arguments[0].style.border<wbr>=<wbr>\"5px<wbr>solid<wbr>yellow\""</wbr></wbr></wbr></wbr></span>,element);<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr>}<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- }<wbr><wbr></wbr></wbr>
<wbr></wbr>
上面的代码WebDriverWait类的构造方法接受了一个WebDriver对象和一个等待最长时间(10秒)。然后调用until方法,其中重写了ExpectedCondition接口中的apply方法,让其返回一个WebElement,即加载完成的元素,然后点击。默认情况下,WebDriverWait每500毫秒调用一次ExpectedCondition,直到有成功的返回,当然如果超过设定的值还没有成功的返回,将抛出异常。
<wbr></wbr>
隐性等待
<wbr></wbr>
隐性等待是指当要查找元素,而这个元素没有马上出现时,告诉WebDriver查询Dom一定时间。默认值是0,但是设置之后,这个时间将在WebDriver对象实例整个生命周期都起作用。上面的代码就变成了这样:
<wbr></wbr>
Java代码<wbr><wbr><a href="http://jarvi.iteye.com/blog/1453662" title="收藏这段代码" style="text-decoration:none; color:rgb(62,115,160)"><img src="http://jarvi.iteye.com/images/icon_star.png" alt="收藏代码" title="[WebDriver]等待页面加载,(转载出自jarvi)" style="margin:0px; padding:0px; border:0px; list-style:none"></a></wbr></wbr>
- import<wbr>java.util.concurrent.TimeUnit;<wbr><wbr></wbr></wbr></wbr>
- <wbr><wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.By;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.JavascriptExecutor;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.WebDriver;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.WebElement;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.firefox.FirefoxDriver;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.support.ui.ExpectedCondition;<wbr><wbr></wbr></wbr></wbr>
- import<wbr>org.openqa.selenium.support.ui.WebDriverWait;<wbr><wbr></wbr></wbr></wbr>
- <wbr><wbr></wbr></wbr>
- <wbr><wbr></wbr></wbr>
- public<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>class</strong></span><wbr>WaitForSomthing<wbr>{<wbr><wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>public</strong></span><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>static</strong></span><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>void</strong></span><wbr>main(String[]<wbr>args)<wbr>{<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,130,0)">//<wbr>TODO<wbr>Auto-generated<wbr>method<wbr>stub</wbr></wbr></wbr></wbr></span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>System.setProperty(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"webdriver.firefox.bin"</span>,<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"D:\\Program<wbr>Files\\Mozilla<wbr>Firefox\\firefox.exe"</wbr></wbr></span>);<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>WebDriver<wbr>dr<wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(127,0,85)"><strong>new</strong></span><wbr>FirefoxDriver();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,130,0)">//设置10秒</span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>dr.manage().timeouts().implicitlyWait(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(192,0,0)">10</span>,<wbr>TimeUnit.SECONDS);<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>String<wbr>url<wbr>=<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"file:///C:/Documents<wbr>and<wbr>Settings/gongjf/桌面/selenium_test/Wait.html"</wbr></wbr></span>;//<wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"/Your/Path/to/Wait.html"</span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>dr.get(url);<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><span style="word-wrap:normal; word-break:normal; line-height:18px; color:rgb(0,130,0)">//注释掉原来的</span><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>dr.findElement(By.id(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"b"</span>)).click();<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>WebElement<wbr>element<wbr>=<wbr>dr.findElement(By.cssSelector(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">".red_box"</span>));<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>((JavascriptExecutor)dr).executeScript(<span style="word-wrap:normal; word-break:normal; line-height:18px; color:blue">"arguments[0].style.border<wbr>=<wbr>\"5px<wbr>solid<wbr>yellow\""</wbr></wbr></wbr></wbr></span>,element);<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- <wbr><wbr><wbr><wbr>}<wbr><wbr></wbr></wbr></wbr></wbr></wbr></wbr>
- }<wbr><wbr></wbr></wbr>
<wbr></wbr>
两者选其一,第二种看起来一劳永逸呀。哈哈