Ways to focus on textbox in selenium

Blurred text with a focus on successIn our one of prev post selenium on textboxt, we have seen how to type or send text into textboxes using selenium and java

There are situations where direct sendkeys doesn’t work, so we need to focus on that text box and then sendKeys to type text, this can be achieved by using

  • JavaScriptExecutor
  • Actions class

 

Using JavaScriptExecutor

Using Actions class

Depending on your application, you can use any one of the above methods to focus on text boxes, the same can be done for any of the web elements present on the web browser.

Above methods can be used if in case sendKeys doesn’t work,

sometimes we need to just focus on a textbox and let’s say that sendKeys works perfectly, then you can just use below one line code to focus…

 

Content posted is based on learning or working experience, please leave comments if anything needs to be added or updated, discuss your queries on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: