Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Press TAB and then ENTER key in Selenium WebDriver

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?

like image 638
Vids Avatar asked Oct 29 '14 08:10

Vids


People also ask

How do you send enter Tab keys in the Webdriver?

webElement. sendKeys(Keys. TAB); //This will enter the string which you want to pass and will press "Tab" button .

How can we press the Enter key from the keyboard in Selenium?

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.

Can Selenium Webdriver press keyboard 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.


2 Answers

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); 
like image 104
Sachin Francis Avatar answered Oct 30 '22 19:10

Sachin Francis


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

like image 32
idophir Avatar answered Oct 30 '22 20:10

idophir