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:-
- Highlight element using javascript.
- Play-down same element using javascript.
- 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