Webdriver with Javascript to validate SVG Canvas objects like Charts

JavaScript in Webdriver

Sometimes Webdriver does not help to find objects and their properties. We can develop Javascript functions and inject them via Webdriver.  

It is good to develop Javascript and inject via Web driver to validate SVG Canvas objects like Charts.

Webdriver provide a “JavascriptExecutor “class for executing java script.

First you need to create “JavascriptExecutor” class object.

JavascriptExecutor js = (JavascriptExecutor) driver;

Now call “executeScript()” method by passing java script code as a argument.
js .executeScript(“java script code”)

Here are some more examples.
String readyState = (String)js.executeScript("return document.readyState");

String title = (String)js.executeScript("return document.title");

String domain = (String)js.executeScript("return document.domain");

WebElement el   = (WebElement)js.executeScript("return document.getElementById('rentc');");

js.executeScript("return document.getElementById('submit').click();");

To inject javascript file,  You should execute script asynch way like below.
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeAsyncScript(jQueryLoader /*, http://localhost:8080/jquery-1.7.2.js */);

Comments

Popular posts from this blog

Testing Shifts with agile automation #RPA #ML

Bots and What Not !!

Need > Want

Automate your everyday tedious tasks and free up time for higher-value work (with Microsoft free RPA solution)

Respect is not earned, It is given ⚘ 🙏

Popular posts from this blog

Typical Project flow with QA Loop in Jira (Atlassian)

Increase ROI in your organization with Automation Testing

Tip to create workflow in JIRA quickly

Headless Automation Testing

QuickTest Pro and Traceability Matrix

AFT (Automation Framework Team) should not take developers' false catches

Testing Priciples & Vocabulary

QA Project Checklist

How to automate test-scenarios which have Java Objects built on JMesa , JQuery, JSON and AJAX technology.