【问题标题】:i am tring to execute my maven project under automation testing using selenium我正在尝试使用 selenium 在自动化测试下执行我的 maven 项目
【发布时间】:2019-09-10 11:29:08
【问题描述】:
String baseUrl = "http://demo.guru99.com/test/login.html";  
driver.get(baseUrl);

// Get the WebElement corresponding to the Email Address(TextField) 
WebElement email = driver.findElement(By.id("email"));

// Get the WebElement corresponding to the Password Field       
WebElement password = driver.findElement(By.name("passwd"));                            

【问题讨论】:

  • 错误指向 WebElement 行
  • 错误是什么?发布完整的堆栈跟踪。
  • @saikiranthotakura 检查 id email 或名称 passwd 的元素是否实际存在/可见
  • @bhusak 是的,有 id email 和 name passwd 的元素
  • @Guy 错误指向 WebElement 行和 id

标签: java selenium selenium-webdriver webdriver webdriverwait


【解决方案1】:

要在电子邮件地址密码字段中发送凭据,您可以使用以下Locator Strategies

  • 代码块:

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    public class A_demo 
    {
        public static void main(String[] args) throws Exception 
        {
            System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
            options.setExperimentalOption("useAutomationExtension", false);
            WebDriver driver = new ChromeDriver(options);
            driver.get("http://demo.guru99.com/test/login.html");
            new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#email"))).sendKeys("saikiran_thotakura");
            driver.findElement(By.cssSelector("input#passwd")).sendKeys("saikiran_thotakura");
        }
    }
    
  • 浏览器快照:

【讨论】:

  • 我使用 .id 时也遇到了同样的错误,请帮帮我
  • @saikiranthotakura 查看更新的答案并告诉我状态。
  • 更新后错误:方法 cssSelector(String) 未定义类型 By
  • 升级到 Selenium v​​3.141.59
  • 是的,我也升级了
猜你喜欢
  • 1970-01-01
  • 2021-09-21
  • 1970-01-01
  • 2016-05-19
  • 1970-01-01
  • 2016-08-29
  • 1970-01-01
  • 2017-08-08
  • 1970-01-01
相关资源
最近更新 更多