document.evaluate

document.evaluate - Cross browser?

孤人 提交于 2019-11-29 12:38:51
问题 I have been looking for a CSS selector function other than Sizzle and I have come across this function. function SparkEn(xpath,root) { xpath = xpath .replace(/((^|\|)\s*)([^/|\s]+)/g,'$2.//$3') .replace(/\.([\w-]+)(?!([^\]]*]))/g, '[@class="$1" or @class$=" $1" or @class^="$1 " or @class~=" $1 "]') .replace(/#([\w-]+)/g, '[@id="$1"]') .replace(/\/\[/g,'/*['); str = '(@\\w+|"[^"]*"|\'[^\']*\')'; xpath = xpath .replace(new RegExp(str+'\\s*~=\\s*'+str,'g'), 'contains($1,$2)') .replace(new RegExp

Is there a way to get element by XPath using JavaScript in Selenium WebDriver?

半腔热情 提交于 2019-11-25 23:36:40
问题 I am looking for something like: getElementByXpath(//html[1]/body[1]/div[1]).innerHTML I need to get the innerHTML of elements using JS (to use that in Selenium WebDriver/Java, since WebDriver can\'t find it itself), but how? I could use ID attribute, but not all elements have ID attribute. [FIXED] I am using jsoup to get it done in Java. That works for my needs. 回答1: You can use document.evaluate : Evaluates an XPath expression string and returns a result of the specified type if possible.