Skip to content Skip to sidebar Skip to footer

Robot Framework: Click Element Using Execute Javascript

I have a xpath selector xpath=//input[@id=image], I want to click on this element using the keyword Execute Javascript ,please help me right the statement I tired the statement

Solution 1:

Following this link Is there a way to get element by XPath using JavaScript in Selenium WebDriver? I have created a keyword for clicking hidden elements. It also works for visible elements.

JS Click Element
[Documentation]
...     Can be used to click hidden elements
...     Dependencies
...         SeleniumLibrary
...         String
[Arguments]     ${element_xpath}# escape " characters of xpath${element_xpath}=       Replace String      ${element_xpath}        \"  \\\"
Execute JavaScript  document.evaluate("${element_xpath}", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotItem(0).click();

Solution 2:

Use below code to click using javascript with XPath in robot framework

${ele}    Get WebElement    //*[text()='Logout']
Execute Javascript    arguments[0].click();     ARGUMENTS    ${ele}

Solution 3:

Instead of finding element and then passing to JS, you can directly find element by ID and click it using JS.

ExecuteJavaScriptdocument.getElementById("element-id").onclick()

Post a Comment for "Robot Framework: Click Element Using Execute Javascript"