如何获得同一页面的当前网址?

时间:2019-05-25 04:14:00

标签: java selenium

 <a href="!#" data-toggle="dropdown">Shuttle 
 <span class="caret"></span></a>
 <ul class="dropdown-menu">
 <li><a href="/client1/shuttle/">Generate Trips </a>
 </li>
 </ul>
 </li>

当我在chrome浏览器中运行此代码时,我得到的是同一页面的正确当前URL,但是当我在chrome无头浏览器中运行此代码时,它将注销屏幕。我也给页面加载超时,但我无法来获取同一页面的当前网址。

我无情地奉献,

ChromeOptions options = new ChromeOptions();
 options.setHeadless(true);
 options.addArguments("--window-size=1440x900");
 driver = new ChromeDriver(options);

// Load the properties File
 props = new Properties();
 props.load(data.class.getClassLoader().getResourceAsStream("application.properties"));
 // Get Url
     driver.get(props.getProperty("url"));

enter image description here我想要Generatetrips标签链接

     WebElement first = 
     driver.findElement(By.xpath(props.getProperty("tabfirst")));
                // click trip generate
                WebElement second = 
     driver.findElement(By.xpath(props.getProperty("tabsecond")));

    Actions a = new Actions(driver);
    a.moveToElement(first).moveToElement(second).click().build().perform();

    driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        System.out.println(driver.getCurrentUrl());


    tabfirst=//a[contains(text(),'Shuttle')]  
    tabsecond=//ul[@class='dropdown-menu']/li[3]/a[contains(text(),'Generate Trips')]

0 个答案:

没有答案