Member-only story
Clicking Element with JavaScript on Robot Framework
Robot framework provides keyword called Execute JavaScript to execute JavaScript codes.
Below code will find the element with provided id value and click on it
Execute JavaScript document.getElementById(‘ID Value’).onclick()
Ex. Execute JavaScript document.getElementById(‘main-header’).onclick()
Below code will find the element with provided xpath value and click on it
Execute JavaScript document.evaluate(‘xpath Value’,document.body,null,9,null).singleNodeValue.click();
Execute JavaScript document.evaluate(‘//div[@id=”individual_learning_plan”]//button[@data-toggle=”dropdown”]’,document.body,null,9,null).singleNodeValue.click();
Note: Make sure all the attribute values on your xpath has wrapped with double quotes(“ ”)
Its better to wrap above code and create generalized keywords on your framework, So that you can reuse them in future developments.