0
点赞
收藏
分享

微信扫一扫

拆分的Webdriver智能等待代码

凯约 2022-08-02 阅读 55

package com.gloryroad.Demo;



import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

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

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

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

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;



public class TestExplictWait {




String url="http://127.0.0.1:8020/HTMLDemo/HTMLPDir/Temp02/Fruit.html";

public WebDriver driver;

@BeforeMethod

public void setUp(){

driver=new FirefoxDriver();

driver.get(url);


}



@AfterMethod

public void tearDown(){

driver.close();

}


@Test

public void ExplictWait(){

WebDriverWait wait=new WebDriverWait(driver, 10);

wait.until(ExpectedConditions.titleContains("水果"));

System.out.println("网页出现了水果标题");

WebElement select=driver.findElement(By.xpath("//option[@value='taozi']"));

wait.until(ExpectedConditions.elementToBeSelected(select));

System.out.println("下拉菜单桃子处于选中状态");

WebElement checkobx=driver.findElement(By.xpath("//input[@id='checkbox']"));

wait.until(ExpectedConditions.elementToBeClickable(checkobx));

System.out.println("处于可点击状态");

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//p")));

System.out.println("标签p存在");

wait.until(ExpectedConditions.textToBePresentInElement(By.xpath("//p"), "水果"));







}



}

举报

相关推荐

0 条评论