Press TAB and then ENTER key in Selenium WebDriver
GenericKeywords.typein(class.variable, PageLength); pagelength is nothing but string.
After this code, I have to give Tab key. I don't know how to give Tab key in Selenium WebDriver?
webElement. sendKeys(Keys. TAB); //This will enter the string which you want to pass and will press "Tab" button .
We can type Enter/Return key in Selenium. We shall use the sendKeys method and pass Keys. ENTER as an argument to the method. Also, we can use pass Keys.
Now, as we discussed, Selenium WebDriver provides two ways to send any keyboard event to a web element: sendKeys() method of WebElement class. Actions class.
Using Java:
WebElement webElement = driver.findElement(By.xpath(""));//You can use xpath, ID or name whatever you like webElement.sendKeys(Keys.TAB); webElement.sendKeys(Keys.ENTER);
In javascript (node.js) this works for me:
describe('UI', function() { describe('gets results from Bing', function() { this.timeout(10000); it('makes a search', function(done) { var driver = new webdriver.Builder(). withCapabilities(webdriver.Capabilities.chrome()). build(); driver.get('http://bing.com'); var input = driver.findElement(webdriver.By.name('q')); input.sendKeys('something'); input.sendKeys(webdriver.Key.ENTER); driver.wait(function() { driver.findElement(webdriver.By.className('sb_count')). getText(). then(function(result) { console.log('result: ', result); done(); }); }, 8000); }); }); });
For tab use webdriver.Key.TAB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With