Press TAB and then ENTER key in Selenium WebDriver

后端 未结 6 1749
臣服心动
臣服心动 2020-12-16 10:26

Press TAB and then ENTER key in Selenium WebDriver

GenericKeywords.typein(class.variable, PageLength); pagelength is nothing but string.

After this code, I h

相关标签:
6条回答
  • 2020-12-16 10:43

    Using Java:

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

    Using C#:

    private IWebDriver driver = new FirefoxDriver();
    IWebElement element = driver.FindElement(By.Name("q"));
    element.SendKeys(Keys.Tab);
    element.SendKeys(Keys.Enter);
    
    0 讨论(0)
  • 2020-12-16 10:47

    In python this work for me

    self.set_your_value = "your value"
    
    def your_method_name(self):      
        self.driver.find_element_by_name(self.set_your_value).send_keys(Keys.TAB)`
    
    0 讨论(0)
  • 2020-12-16 10:47

    Be sure to include the Key in the imports...

    const {Builder, By, logging, until, Key} = require('selenium-webdriver');

    searchInput.sendKeys(Key.ENTER) worked great for me

    0 讨论(0)
  • 2020-12-16 10:50
    WebElement webElement = driver.findElement(By.xpath(""));
    

    //Enter the xpath or ID.

         webElement.sendKeys("");
    

    //Input the string to pass.

         webElement.sendKeys(Keys.TAB);
    

    //This will enter the string which you want to pass and will press "Tab" button .

    0 讨论(0)
  • 2020-12-16 10:59

    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);
    
    0 讨论(0)
  • 2020-12-16 11:04

    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

    0 讨论(0)
提交回复
热议问题