selenium-webdriver笔记六

上一篇 / 下一篇  2012-12-29 00:30:44 / 个人分类:selenium

51Testing软件测试网|pnB/I2p z/R4HL Q
*
捕作弹出框并确认

k[3Ut2t0

Alert alert = driver.switchTo().alert();51Testing软件测试网 g vy[Z\$E&E

alert.accept();

rgW!BJ2Mb0

 51Testing软件测试网 og%B+pbM|`

alert的其他方法:51Testing软件测试网Hf]1m3Q5C,^A j

dismiss

g ?ebXE:T}!i0

gettest

7E4}_z4aLK0

sendkeys

h~n,u.w0]/|0

 

c7Vv;\5IU {U0

*隐式等待

.[:l$N0L zA6L0

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);51Testing软件测试网z!{1]9_twv*Wt

*显式等待51Testing软件测试网;is*~*qx:DU9^,S)qI

1.WebDriverWait wait = new WebDriverWait(driver, 10);51Testing软件测试网;wM t%fU%p;g

WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));51Testing软件测试网[X3u[j7xI

需要import org.openqa.selenium.support.ui.ExpectedConditions;

k@3Gx-ie;aX"C0

import org.openqa.selenium.support.ui.WebDriverWait;

B:I*M#WL1I#X0

ExpectedConditions的其他方法51Testing软件测试网:z0sNM&x6WI

alertIsPresent() 51Testing软件测试网~1Tq_.IK9L~j

textToBePresentInElement(By locator, java.lang.String text)51Testing软件测试网#Gx1? ] Q;u{C*~!S,k`

……51Testing软件测试网 })x7s2My

2.

;iuM{.oa0M0

WebElement myDynamicElement = (new WebDriverWait(driver, 10))

#I#jd5Bs&C0

  .until(new ExpectedCondition<WebElement>(){51Testing软件测试网!noUF7\tz0uVjj

         @Override

!wa@#i,m6F$B7Y0

         public WebElement apply(WebDriver d) {51Testing软件测试网2I|&\l-aX8G

                 return d.findElement(By.id("myDynamicElement"));

EgRg}I$y B0

         }});51Testing软件测试网;\o*O;\;]e%g

 51Testing软件测试网4U[%Cy;\%L5q:^8|

需要import org.openqa.selenium.support.ui.ExpectedCondition;

:F!fy2{b0a0

 51Testing软件测试网0Y;m5w#K;SEQS]

*遍历select

Dp/TxfC@:f8[0

WebElement select = driver.findElement(By.tagName("select"));

cdlL!`h[0

List<WebElement> allOptions = select.findElements(By.tagName("option"));

M S G`1Wrt0

for (WebElement option : allOptions) {

;N2J2D9g7|/an&q4Y m0

 System.out.println(String.format("Value is: %s", option.getAttribute("value")));

W6dGQ8} j0

                     option.click();51Testing软件测试网Z%U/qok*C L7f

 }51Testing软件测试网m-_t QJ2`}H

需要导入java.util.List;51Testing软件测试网7^0To QWn

 51Testing软件测试网-bc\ x6\ U)}N |8m

51Testing软件测试网ECb)E^


TAG:

 

评分:0

我来说两句

Open Toolbar