【发布时间】:2018-10-31 17:53:24
【问题描述】:
我实际上刚刚开始使用 Selenium 学习 Java,但我无法接收当前的 URL。 Selenium 返回起始 URL,而不是当前 URL。
看起来,implicitlywait() 不起作用,还是我做错了什么?
package SeleniumPackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.util.concurrent.TimeUnit;
public class SeleniumClass {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://learn.letskodeit.com/p/practice");
WebElement benzRadioBtn = driver.findElement(By.id("benzradio"));
benzRadioBtn.click();
WebElement hondaRadioBtn = driver.findElement(By.id("hondaradio"));
hondaRadioBtn.click();
WebElement bmwRadioBtn = driver.findElement(By.id("bmwradio"));
bmwRadioBtn.click();
WebElement benzCheckBox = driver.findElement(By.id("benzcheck"));
benzCheckBox.click();
Select dropdown = new Select (driver.findElement(By.id("carselect")));
dropdown.selectByValue("honda");
WebElement element = driver.findElement(By.id("product"));
System.out.println(element.getText());
driver.findElement(By.linkText("Terms of Use")).click();
String currentURL = driver.getCurrentUrl();
System.out.println(currentURL);
【问题讨论】:
标签: java selenium selenium-webdriver