【问题标题】:Testing java class using selenium and cucumber使用 selenium 和 cucumber 测试 java 类
【发布时间】:2020-11-06 16:00:51
【问题描述】:

user 应该能够选择首选语言 网站的内容应该使用以下网站以所选语言加载?

这是我当前的代码如何修改以匹配这种情况?

ublic class Steps {             

    WebDriver driver;           
            
    @Given("^Open the Firefox and launch the application$")                 
    public void open_the_Firefox_and_launch_the_application() throws Throwable                          
    {       
       System.setProperty("webdriver.gecko.driver", "E://Selenium//Selenium_Jars//geckodriver.exe");                    
       driver= new FirefoxDriver();                 
       driver.manage().window().maximize();         
       driver.get("https://www.gov.lk/welcome.html");                   
    }       

    @Then("^Reset the credential$")                 
    public void Reset_the_credential() throws Throwable                             
    {       
       driver.findElement(By.name("btnReset")).click();                 
    }       
}       

【问题讨论】:

  • 您尝试点击哪种语言firstsecondEnglish
  • 英语优先...
  • 你想点击英文,那是你的方案,对吧?
  • 是的......

标签: java selenium maven testing cucumber


【解决方案1】:

该元素是启用了JavaScript 的元素,因此要在该元素上使用click(),您需要将WebDriverWait 用于elementToBeClickable(),并且您可以使用以下任一Locator Strategies

  • cssSelector:

    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.english"))).click();
    
  • xpath:

    new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='english']"))).click();
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-24
    • 1970-01-01
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多