webdriver中select下拉框选择
2017-02-06 本文已影响0人
红木杉2018

package com.selenium.gen;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.WebElement;
public class Select {
public static void main(String[] args) {
// TODO Auto-generated method stub
//定义一个路径
String path="D:\\jase\\select.html";
//打开浏览器
WebDriver driver=new FirefoxDriver();
//打开页面
driver.navigate().to(path);
//定位select元素
WebElement elemnt=driver.findElement(By.id("ShippingMethod"));
//定位option中的元素
elemnt.findElements(By.tagName("option")).get(1).click();
//关闭浏览器
driver.quit();
}
}