Posts

Showing posts from November, 2017

Misc 02: Adding Code Snippet in Blogger

Image
Code Snippet in Blogger To add good looking code snippet on the blogger page just go to the http://hilite.me/ and convert your code as per your blogger theme. I am using the generated CSS on my blog. You can see the example by clicking here .

JAVA Script Executor Code to get the Value (same as getText() method)

Get the element value using Javascript Executor in Selenium WebDriver To get the text of an element we can also use the Javascript Executor. Below is the code to get the text and store in a String variable. 1 2 3 4 5 6 7 @FindBy(id = Checkbox. financialAssistanceAccountEmailId ) public WebElement financialAssistanceAccountEmail; //To get value JavascriptExecutor executor = (JavascriptExecutor) driver; String visit = (String) executor. executeScript ( "return arguments[0].value" , financialAssistanceAccountEmail);

JAVA Script Executor Code to Click on an Element

Click on an Element in Selenium WebDriver Sometimes click() method does not work because two views are loaded at the same time on a page. In this case, we can use the JavascriptExecutor to get the work done. Below is code to click on an element using Javascript Executor. 1 2 3 4 5 6 7 @FindBy(id = Checkbox. financialAssistanceAccountEmailId ) public WebElement financialAssistanceAccountEmail; //Click to element JavascriptExecutor executor = (JavascriptExecutor) driver; executor. executeScript ( "arguments[0].click()" , financialAssistanceAccountEmail);

JAVA Script Executor Code to Scroll to an Element

Scroll to an Element in Selenium WebDriver Some times there is need to scroll to an element and perform some operations. We can use the JavascriptExecutor to scroll down to an element. Below code is used to scroll down to an element. We have used the getLocation().y to get the y axis position of the element. In the same way we can use the x axis position of the element. 1 2 3 4 5 6 7 @FindBy(id = Checkbox. financialAssistanceAccountEmailId ) public WebElement financialAssistanceAccountEmail; //Scroll to element JavascriptExecutor js = (JavascriptExecutor) driver; js. executeScript ( "window.scrollTo(0," +financialAssistanceAccountEmail. getLocation (). y + ")" );