Home > database >  I just want to send keys to search box how to sendkey()
I just want to send keys to search box how to sendkey()

Time:12-31

https://www.beymen.com

I am new to Selenium. I just want to send keys to search box how to sendkey() this textbox idk. i can't

CodePudding user response:

So I went to beymen.com and found

<input maxlength="50" placeholder="Search for Product, Brand"  aria-activedescendant="" aria-autocomplete="list" aria-controls="3-suggestions">

which you can by any of it's attributes like so

driver.findElement(By.cssSelector("input.default-input.o-header__search--input")).sendKeys("a");

I recommend using webdriver waits as well

WebDriverWait wait = new WebDriverWait(driver,30);
wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.default-input.o-header__search--input"))).sendKeys("a");

CodePudding user response:

So there is this method :

driver.findElement(By.xpath("/your/xpath/here")).sendKeys("Whatever you want to write");

From your question it's not clear exactly what you want to do so just to know, this method can also be used to send keyboard keys:

//press return button on a specific element
driver.findElement(By.xpath("/your/xpath/here")).sendKeys(Keys.RETURN);
  • Related