我刚开始学习使用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);