In Selenium IDE, how to get the value of the base url

后端 未结 7 1519
栀梦
栀梦 2021-02-04 01:19

Is it possible to retrieve the value of the base url from inside a Selenium script (a plain HTML-saved script from Selenium IDE)?

What I\'m trying to do

7条回答
  •  有刺的猬
    2021-02-04 01:57

    You can use Selenium driver to get the current Url as a String, then convert the object into a URL object. Once you have done that, the Java URL class has some methods that you can use to get parts of the URL.

    String url = driver.getCurrentUrl();
    String domain = getDomainName( url );
    public static String getDomainName( String url ) throws URISyntaxException {
        URI uri = new URI(url);
        String domain = uri.getHost();
        return domain.startsWith("www.") ? domain.substring(4) : domain;
    }
    

提交回复
热议问题