我想从我的java类中获取在selenium测试类中声明的url(baseUrl = "http://google.com";
)。我如何获取url
有没有selenium api 类。请推荐我
public class SeleJunit {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://localhost:8080/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testSeleJunit1() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.linkText("New Item")).click();
driver.findElement(By.id("name")).click();
driver.findElement(By.id("name")).clear();
driver.findElement(By.id("name")).sendKeys("i18n2");
driver.findElement(By.name("mode")).click();
driver.findElement(By.id("ok-button")).click();
new Select(driver.findElement(By.name("_.compressionLevel"))).selectByVisibleText("System Default");
// ERROR: Caught exception [Error: Dom locators are not implemented yet!]
driver.findElement(By.id("side-panel")).click();
driver.findElement(By.id("yui-gen30-button")).click();
driver.findElement(By.linkText("Jenkins")).click();
}
最佳答案
driver.getCurrentUrl()
方法会给你你想要的。它将返回完整的 URL(例如 this ),因此您需要截掉 .com 之后的字符串。
关于java - 如何从java中的selenium测试类获取url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22091979/