Selenium: How do I execute a function or Xpath expression in my test?

Is there a way to execute some Xpath code in a Selenium test? I know that you can execute javascript, but I'm looking for a way to execute some Xpath code outside of just looking for an element on the page.

Does anyone come across this?

+3
source share
5 answers

I believe the accepted answer is incorrect. I am currently studying Selenium WebDriver with Java, and I was directed to the next blog post to learn how to perform XPath functions in Selenium 2 to manage xpath variables. I believe that this is what you are looking for.

http://automationtricks.blogspot.com/2010/09/how-to-use-functions-in-xpath-in.html

+1

, XPath XPath 2.0. 2.0. , XPath .

+2

, . , Selenium Developers , , , Selenium Developer, StackOverflow:)

, , , ( , Selenium). " " (. JS- , ). ( ), , : Selenium XPath.

, Firefox, JS- Firefox XPath . storeEval-. , , Selenium XPath Selenium JS. . , Selenium XPath, , .

, ? , , .

0

W3C XPath 1.0, XPath 1.0 , : http://www.w3.org/TR/xpath#section-String-Functions

, "end-with" -

//input[substring(@id, string-length(@id) - string-length('<idSuffix>') +1) = '<idSuffix>']

( id '<idSuffix>').

0

1177 htmlutils.js 1.0.1 Selenium ( eval_xpath(), XPath):

    var result = xpathResult.iterateNext();

, XPathResult, iterateNext() , . Selenium , XPath node, , .

, htmlutils.js, 1177-1181 - :

    var iterable =
     xpathResult.resultType == xpathResult.ORDERED_NODE_ITERATOR_TYPE ||
     xpathResult.resultType == xpathResult.UNORDERED_NODE_ITERATOR_TYPE;

    if (iterable) {
     var result = xpathResult.iterateNext();
     while (result) {
         results.push(result);
         result = xpathResult.iterateNext();
     }
    } else if (xpathResult.resultType == xpathResult.NUMBER_TYPE) {
     results.push(inDocument.createTextNode(xpathResult.numberValue));
    }

, , DOM TextNode , , , Selenium. Selenium getText TextNodes ( String), -

int count = Integer.parseInt(selenium.getText("xpath=count(//td) + 1"), 10);

selenium DefaultSelenium, SeleniumRC Java-, . , , getXpathCount(), XPathResult, , .

, , , XPath . XPath Selenium eval_xpath() , , , .

0

Source: https://habr.com/ru/post/1703316/


All Articles