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

后端 未结 7 1527
栀梦
栀梦 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 02:06

    After struggling with using the verifyLocation selenium IDE command (which only gives you the host name to verify, and will include parts of the query string which may be widely random at runtime) the way to verify the current url and path which is the most flexible (so far) is to use the "verifyEval" command and use javascript to parse out the portion of the url I want to test:

    verifyEval | window.location.pathname=="/my/stuff" | true
    

    You can put any of the location properties that javascript supports and test those (see https://gist.github.com/jlong/2428561)...

    Command: verifyEval
    Target: window.location.pathname=="/my/stuff"
    Value: true
    

    OR for example:

    Command: verifyEval
    Target: window.location.hostname=="example.com"
    Value: true
    

    Or feel free to make combinations

    Command:verifyEval
    Target: window.location.protocol+'//'+window.location.hostname+window.location.pathname=='http://example.com/my/stuff'
    Value:true
    

提交回复
热议问题