~7QCZ)|K
kw:Kt0*捕作弹出框并确认51Testing软件测试网pR,Y m1Nk IM
Alert alert =
driver.switchTo().alert();51Testing软件测试网P5u,[ki k2z
alert.accept();51Testing软件测试网MiRD4fB[Y?I4^2e
mb6\4q%};d:m0alert的其他方法:
-~7qe2HlD"S0dismiss
!u#@U[b0gettest51Testing软件测试网rF*`A
\9Wh
sendkeys
;a-q6DCb/D4~
Ku!N0 51Testing软件测试网\F9Q3D#T%`UBfT
a
*隐式等待
,gAz$`!@\0driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);51Testing软件测试网.L-py
H%A0D'c:?
*显式等待
^+HtQ P5}j01.WebDriverWait wait = new WebDriverWait(driver,
10);51Testing软件测试网/yKB r [S&q
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));51Testing软件测试网%Q1xQ!d`z-b
需要import org.openqa.selenium.support.ui.ExpectedConditions;51Testing软件测试网U5](V
AGaE
import
org.openqa.selenium.support.ui.WebDriverWait;
@X``-fB0ExpectedConditions的其他方法
0yq(xI~|hy0alertIsPresent()
5l+h~$~5mrg!M%~0textToBePresentInElement(By locator,
java.lang.String text)51Testing软件测试网0sC+i+J-ICy
……
n7G-ra1cm&XL02.
ck;Ej%yb(cLl0WebElement myDynamicElement = (new
WebDriverWait(driver, 10))
S/PS;_&Xo0 .until(new ExpectedCondition<WebElement>(){51Testing软件测试网A+Qw;R6MH)@!S]
@Override51Testing软件测试网"X
?oyQ%]p
public WebElement apply(WebDriver d) {51Testing软件测试网0x{.Nb$dO?o5_
return d.findElement(By.id("myDynamicElement"));51Testing软件测试网X"uo'B5{v){l
}});51Testing软件测试网U `Mv9m1[(j
51Testing软件测试网Px9U-_z)mV
需要import
org.openqa.selenium.support.ui.ExpectedCondition;51Testing软件测试网"JkFe+F_@
%{n'pK@gDu`0*遍历select51Testing软件测试网m`&E.r
i ^Q
WebElement select
= driver.findElement(By.tagName("select"));
z$ch`v'v.I+[9[0List<WebElement>
allOptions = select.findElements(By.tagName("option"));
4q1vjGo*e;@0for (WebElement
option : allOptions) {
r3l
^'tmu[_i7C0 System.out.println(String.format("Value
is: %s", option.getAttribute("value")));
lAGl?^0 option.click();
#EH#bl:GF&g8X8|+\4Z0 }51Testing软件测试网#T~Q8k5N;F'Wp~#q
需要导入java.util.List;51Testing软件测试网$v#qV{yq
JDF
orZ jyF D$`!n0(z&nq$t]@M(`0