Saturday 16 July 2016

Highlight Element in Selenium WebDriver

  I missed highlighting object feature of QTP when I used to debug my selenium API call on webelement. Number of times I wondered, why didn't by default any method is provided to perform highlight action. But I no longer wish for same as I have found work around.  

      Remember this - ‘JavaScript comes in handy to perform any fancy tasks on DOM.’

Logic to perform highlight WebElement in Selenium WebDriver:-


       To create highlight effect, as in QTP, we don't just need to highlight the element but also have to de-emphasize/play down the same element. Highlighting element once is not enough, as the operation would be fast and we may don't realise highlighting effect. Better we break down logic as in below steps:-
  1. Highlight element using javascript.
  2. Play-down same element using javascript.
  3. Perform above two actions in a loop for significant time.

Below code demonstrate use of JavascriptExecutor to perform highlight element in Selenium WebDriver.

As you can see in above code, method highlightElement accepts WebElement as parameter and perform highlight operations for 5 seconds [i<5].

This is all for now.
Cheers!!

0 comments:

Post a Comment

Copyrights held by Amol Chavan. Powered by Blogger.