1

Hi I am trying to execute a JavaScript in VBA in the native excel application using Selenium Wrapper.

The following code executes a JavaScript on Chrome Console and gives me my expected output.

$x("//label[text()[contains(.,'British')]]")[0].children[1].children[0].click()

To execute JavaScript usually it needs to be in double quotes however this is not accepted by VBA since it has two double quotes.

driver.ExecuteScript("$x("//label[text()[contains(.,'British')]]")[0].children[1].children[0].click()")

I tried to define it as a string in another variable with the concatenation of the values, but it is still giving me error.

I don't want findElementByXpath with click method. Would request if anyone knows a workaround of this.

Edit 1 instead of $x which works on chrome, using document.evaluate works in webdriver.

1 Answer 1

1

For what it's worth,

driver.ExecuteScript("$x("//label[text()[contains(.,'British')]]")[0].children[1].children[0].click()")

should be written like this:

driver.ExecuteScript("$x(""//label[text()[contains(.,'British')]]"")[0].children[1].children[0].click()")
Sign up to request clarification or add additional context in comments.

1 Comment

Since you cannot click an element which is not displayed using webdriver, but executing a javascript works even if the element is not displayed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.