程序-练习Web表
- 打开浏览器
- 打开网址: http://toolsqa.com/automation-practice-table/
- 获取单元格"Dubai"值并打印
- 点击第一行最后一列的"details"链接
- 用动态法获取单元格"Dubai"值
- 打印出"Clock Tower Hotel"行所有的值
- 关闭浏览器
package automationFramework;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class DynamicWebTables {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.gecko.driver", "F:\\\\workspace\\ToolsQA\\OnlineStore\\geckodriver-v0.26.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
//打开网址: http://toolsqa.com/automation-practice-table/
String bdURL = "http://toolsqa.com/automation-practice-table";
driver.navigate().to(bdURL);
//获取单元格"Dubai"值并打印
String sCellValue = driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr[1]/td[2]")).getText();
System.out.println(sCellValue);
//点击第一行最后一列的"details"链接
driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr[1]/td[6]/a")).click();
Thread.sleep(5000);
String sRowValue = "Clock Tower Hotel";
//用动态法获取单元格"Dubai"值
String sRow = "1";
String sCol = "2";
String Dy_sCellValue=driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr["+sRow+"]/td["+sCol+"]")).getText();
System.out.println(Dy_sCellValue);
//打印出"Clock Tower Hotel"行所有的值
for(int i=1;i<=5;i++) {
String sValue=null;
sValue=driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr[" + i + "]/th")).getText();
if(sValue.equalsIgnoreCase(sRowValue)) {
for(int j=1;j<=5;j++) {
System.out.println(driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr[" +i+"]/td["+j+"]")).getText());
}
break;
}
}
driver.quit();
}
}