Selenium strange behavior when attempting to select a specific input box

19 views
Skip to first unread message

Eric Liu

unread,
Feb 4, 2020, 7:12:23 AM2/4/20
to Selenium Developers
I've been using the same code to select and input text into an input box with no errors until recently. The code looks something like this:

public class page {
   private By input = By.cssSelector("input");

   public void setInput(String text) {
   driver.findElement(input).click();
   driver.findElement(input).sendKeys(text);
   }
}

I create a page object and call setInput() like so:

page p = new page(driver);
p.setInput("asdf");

This methodology has been working throughout my entire code base for months up until now. Selenium seems to be behaving very strangely and will crash when attempting to select and input into the box.
However, if I just explicitly write out

driver.findElement(input).click(); 
driver
.findElement(input).sendKeys(text);

in my testing class instead of creating a page object and calling setInput(), it works fine. This is very strange because only this particular method/input box behaves like so. All other input boxes on the page behave normally. 
I am using chromeDriver. Has anyone else encountered these issues? Thanks


Jonathan Herbaut

unread,
Feb 17, 2020, 5:16:51 AM2/17/20
to Selenium Developers
Are you forced to use the click function before you use your sendKeys method ?
In C#, I use the clear function before using my sendKeys function.
This would help us if you say to us when you get your exception and what is the nature of your exception

iranibalooch noor

unread,
Feb 17, 2020, 5:17:15 AM2/17/20
to selenium-...@googlegroups.com

متشکرم بسیارمفیدواقع شد

در تاریخ ۵ فوریهٔ ۲۰۲۰ ۰:۱۲، "Eric Liu" <ericl...@gmail.com> نوشت:
--
You received this message because you are subscribed to the Google Groups "Selenium Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-developers+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-developers/49af3079-6a8a-492a-914e-9b506eeea03c%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages