Search This Blog

Breaking

Wednesday, 20 October 2021

[Fix] Selenium getText() is returning empty text in Jenkin while working fine in Local

 Today I encountered a weird issue where in my local. I am able to retrieve element text with the help of selenium getText() method while in jenkin machine, it was giving empty value for the element text.











It was happening because of the different view port in Jenkin. Mean, in Jenkin, that field was not visible because the size of the window was different there.

To fix this issue, rather then getting the text via getText() method, I used getAttribute method.

And I gave the property as "innerText".

So I replaced my getText() to getAttribute("innerText") and hurray, It returned the text now.

if this also doesn't work for you, try with below options:

1. getAttribute("innerHTML")

2. getAttribute("textContent")


This saved my lot of time because I was using scrollView method else to navigate that element first and then retrieve the text value.



No comments:

Post a Comment