1

I'm having a hard time trying to use Execute Javascript driver.findElement(By.xpath in Robot Framework

I have no issues updating the value of an element using this JS method below

document.getElementById("Some_ID").value = "Some Value"

Robot can find the document.getElementById method but can't find the driver.findElement(By.xpath method

Does anyone know how I would go about using the method/instantiating the driver?

The error I get is this:

WebDriverException: Message: unknown error: driver is not defined

4
  • Have you initialized your robot? ie: Webdriver driver = new [...] The error suggests that the script doesn't know driver Commented Dec 14, 2018 at 16:51
  • driver.findElement() is not a JS method, it is a selenium's one - thus the error. Commented Dec 14, 2018 at 17:42
  • 1
    can you show the actual code you're using? Do you have a python-based keyword that gives you access to driver? Commented Dec 14, 2018 at 18:40
  • Perhaps you can also elaborate on what it is you want to achieve functionally. Perhaps there is a better way of doing it without the need for custom javascript work. Commented Dec 17, 2018 at 15:49

1 Answer 1

1

driver.findElement(By.xpath) is not a Javascript method. It is a method of Selenium. As you said, javascript only has document.getElementById method.

If you still want to use xpath with javascript method, use Assign Id To Element keyword (see more at HERE). It will assign an ID for an xpath locator. Then use that ID in document.getElementById method

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

1 Comment

This was perfect. Thank you very much!

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.