2014-10-29 2 views
13

Premere TAB e quindi INVIO chiave in selenio WebDriver TestNGPremere TAB e quindi INVIO chiave in selenio WebDriver TestNG

GenericKeywords.typein (class.variable, pagelength); La lunghezza della pagina non è altro che una stringa.

Dopo questo codice, devo dare il tasto Tab. Non so come dare il tasto Tab in Selenium WebDriver TestNG?

+0

grazie in anticipo – Vids

+0

TestNG non è contribuire a premere il tasto. Puoi farlo tramite Selenium WebDriver, TestNG viene utilizzato per la verifica/asserzione test –

+0

Poiché stai utilizzando il framework TestNG, è facile capire che stai utilizzando il linguaggio Java. –

risposta

29

Utilizzo di 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); 
+0

grazie @sachin – Vids

+0

ha funzionato per te? –

+0

sì !! lavoro fine siringa – Vids

4

in javascript (node.js) questo funziona per 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); 


    }); 
    }); 
}); 

Per uso scheda webdriver.Key.TAB

+0

Ciao idophir, sto scrivendo test mobili automatizzati usando Node.js e wd.js, ma per qualche ragione questo non funziona per me. In un nodo repl, quando digito require ('wd'). Key, non è definito. Quando digito require ('wd'). SPECIAL_KEYS, ottengo un elenco di chiavi che includono la scheda. Ma quando faccio questo: '.sendKeys (wd.SPECIAL_KEYS.Tab)' invia una faccina. Non divertito! haha sai se c'è un modo per farlo con wd per l'automazione mobile? Ecco cosa sto usando: https://www.npmjs.com/package/wd – Matthew

1

Utilizzo di Java:

private WebDriver driver = new FirefoxDriver(); 
WebElement element = driver.findElement(By.id(""));//Enter ID for the element. You can use Name, xpath, cssSelector whatever you like 
element.sendKeys(Keys.TAB); 
element.sendKeys(Keys.ENTER); 

con C#:

private IWebDriver driver = new FirefoxDriver(); 
IWebElement element = driver.FindElement(By.Name("q")); 
element.SendKeys(Keys.Tab); 
element.SendKeys(Keys.Enter); 
0
WebElement webElement = driver.findElement(By.xpath("")); 

// Inserire l'XPath o ID.

 webElement.sendKeys(""); 

// Inserire la stringa da passare.

 webElement.sendKeys(Keys.TAB); 

// Questo inserirà la stringa che si desidera passare e premerà il pulsante "Tab".

0

Assicurati di includere l'Key delle importazioni ...

const {Builder, per, la registrazione, fino a quando, Key} = require ('selenio WebDriver');

searchInput.sendKeys(Key.ENTER) ha lavorato molto per me