2

I am trying to pass an xpath as a parameter(redirectButton):

WebElement zoomLogo = driver.findElement(By.xpath(redirectButton));

Line in testsuite.xml looks like this:

            <parameter name="redirectButton" 
        value="&quot;//img[@alt='zoom logo colour long']&quot;)" />

But when I try to run the test through the testsuite file using testng it shows the following error:

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '"//img[@alt='zoom logo colour long']")' is not a valid XPath expression.

I am sure I have proper xpath because when I paste it directly into the code then everything works fine, but when I try to do it via parameter its not working.

Is it possible to do it by parameters?

1
  • The line in the testsuite.xml should be <parameter name="redirectButton" value="//img[@alt='zoom logo colour long']" /> (without the &quot; and the ) at the end) because the xpath itself is //img[@alt='zoom logo colour long']. If you write the xpath as String in Java you have to place it in quotes, but that is how strings are defined in Java and is not part of the xpath expression. Commented Feb 9, 2021 at 21:59

1 Answer 1

1

This error message...

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '"//img[@alt='zoom logo colour long']")' is not a valid XPath expression.

...implies that the which you have used was not a valid XPath expression.

Seems you were almost there. You need to remove the two &quot; characters and the extra ) to make it a valid xpath expression as follows:

<parameter name="redirectButton" value="//img[@alt='zoom logo colour long']" />

References

You can find a couple of relevant detailed discussions in:

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help and explanation!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.