As we have seen in my previous posts, we can Get Page Title, Get Domain Name, Generate Alert using java script executor interface of selenium webdriver software testing tool. Using webdriver, we can perform many different actions on software web page but for that you should be aware about this kind of things. We can execute any other java scripts too using this interface of webdriver.
Let me give you one more practical example for the same. Sometimes if you want to highlight element of software web application page then you can use javascript executor. If you remember, we were using "highlight" command in selenium IDE to highlight any element of web page.
If you VIEW WEBDRIVER EXAMPLE ON THIS POST, i have created function named HighlightMyElement and written few syntax of javascript executor. Now if i want to highlight any element of software web page then simply i need to call that function as shown in bellow example. You can change your preferred highlighting color in that example.
HighlightMyElement(driver.findElement(By.xpath("//input[@name='fname']")));
driver.findElement(By.xpath("//input[@name='fname']")).sendKeys("My Name");
HighlightMyElement(driver.findElement(By.xpath("//button[@onclick='myFunction()']")));
WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#submitButton")));
HighlightMyElement(driver.findElement(By.cssSelector("#submitButton")));
driver.findElement(By.cssSelector("#submitButton")).click();
In above example, HighlightMyElement will highlight the all 3 targeted elements on software web page by calling function.
Hi..Could you please let us know how do we highlight element in the "HighlightMyElement" function ?
ReplyDeleteDo you run above test? It will show you how to do It.
Deleteabove script give complitiem error
ReplyDeleteSorry Got it
ReplyDeleteThis Script is not working for Checkbox and radio buttons ??
ReplyDelete