Skip to content
Advertisement

How to pass web element from Python selenium to Java?

I am making a program that finds all the elements of a webpage with the word “Pens” and changes the text to asteriks. Here is the portion of my code I am having issues with:

JavaScript

The code only works for elements that have an ID. I would like to send the Xpath of the element but the only methods of ‘document’ are .getElementById(), .getElementByClassName(), .getElementByName(), and .getElementByTagName(). I have a function that returns the absolute xpath of an element so all I need is a way to send that to the Java script to reference.

Advertisement

Answer

JavaScript

you should use document.evaluate , now elem will have the webelement you need

https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement