Quick q: Code (Text): if (document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue == "<b>You approach the massive omelette...</b>"){ console.log("omelette content value found"); document.forms[1].submit(); //leave } when I tested document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null in console, it returned: Code (Text): <b>You approach the massive omelette...</b> however, the == expression keeps returning false when it is blatantly true. I figured the problem was that document.evaluate isn't returning a string of text to compare, so I tried: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.toString(); and it returned: Code (Text): "[object HTMLElement]" How do I get around this, in order to check the value of the xpath? tl;dr can't figure out how to access value of document.evaluate'd xpath Thanks!
The returned code is " <b>You approach the massive omelette...</b>" note the space at the beginning (and possible the end). The code you are looking for is "<b>You approach the massive omelette...</b>" with no spaces. This could well be your problem
Thanks for the response! Totally my bad, I copied it wrong with the space. Console logs on the page, with/without space: Without space: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue == "<b>You approach the massive omelette...</b>" false With space: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue == " <b>You approach the massive omelette...</b>" false EDIT: I read about the parameter for return type of xpath's document.evaluate hoping that changing XPathResult to the appropriate String parameter would work: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.STRING_TYPE, null).singleNodeValue Error: TYPE_ERR: DOM XPath Exception 52 XPath Exception 52? What the hell? Googled it, What do I do in order to use the result of document.evaluate / make it a string? :-\
That is because Try either: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.toString().trim() == "<b>You approach the massive omelette...</b>"; Or Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.STRING_TYPE, null).trim() == "<b>You approach the massive omelette...</b>";
Thanks for the help! The problem is that any functional code (ie: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.toString().trim() ) returns Code (Text): "[object HTMLElement]" So that this statement is true: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.toString().trim() == "[object HTMLElement]" true However, I want the actual value of the HTMLElement. Also, for the other one, Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.STRING_TYPE, null).trim() can't .trim() because it's not a string. if we .toString(); : Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.STRING_TYPE, null).toString() "[object XPathResult]" and then trim the string result: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.STRING_TYPE, null).toString().trim(); "[object XPathResult]" we get the same Code (Text): "[object XPathResult]" Problem is that we can't use this as a string of text: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.STRING_TYPE, null).toString().trim() == "<b>You approach the massive omelette</b>" false only comparable this [xpath] object: Code (Text): document.evaluate("//*[@id='content']/table/tbody/tr/td[2]/center/p[1]/b", document, null, XPathResult.STRING_TYPE, null).toString().trim() == "[object XPathResult]" true Thanks for the help, guys!