java - 我正在尝试使用 selenium 在自动化测试下执行我的 maven 项目
问题描述
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"));
解决方案
要在电子邮件地址和密码字段中发送凭据,您可以使用以下定位器策略:
代码块:
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"); } }
浏览器快照:
推荐阅读
- ajax - 使用 AJAX 向 MVC 控制器发送数据
- python - 如何解决 ValueError:真值
- android - 如何解决 admob 收入问题
- c++ - 为什么我的 TcpSocket 接收到完全相同的数据?
- ruby-on-rails - 相关产品只带来一个
- git - “权限被拒绝(公钥)”仅在特定网络上(已配置 SSH 密钥)
- html - 我如何设置身份验证保护以仅允许管理员使用管理仪表板(ngx-admin)?
- spring-boot - 基于 OAuth2 的登录到 localhost:8080 使用 Google 导致重定向到相同的登录页面
- javascript - 根据鼠标指针放大对象
- amazon-web-services - 使用 Cloudflare 在 AWS Lambda 上部署 SSR Nuxt.js?