【发布时间】:2022-07-18 05:26:32
【问题描述】:
所以我从一个登录 URL 开始(“https://LOGIN-URL.com”),我使用发送密钥方法发送登录凭据的密钥值,几秒钟后,验证凭据和新 URL使用主页加载(“https://HOME-PAGE.com”),我必须在其中执行一些操作,然后单击一个按钮以移动到具有不同 URL 的下一页,例如(“https://transactions -tester123.com")
我如何通过 Java Selenium UI 自动化实现这一点?
下面我附上了代码,我可以在其中获取登录凭据部分,但无法在新 URL 中执行操作
driver.get("https://LOGIN-URL.com");
driver.manage().window().maximize();
System.out.println(" User trying to login");
driver.findElement(By.xpath("//input[@id='username']")).sendKeys("hello");
driver.findElement(By.xpath("//input[@id='password']")).sendKeys("password");
driver.findElement(By.xpath("//span[@id='ui-id-44']")).click();
System.out.println("Login successful");
System.out.println("Now user in Home Page");
【问题讨论】:
-
请详细说明“句柄”是什么意思。
-
您能否确认登录验证后,主页和交易页面是否在同一个浏览器窗口和选项卡上打开?如果是,那么您可以继续将定位器策略和脚本添加到同一文件中,它将按预期工作。
-
是的,相同的浏览器、相同的窗口、相同的选项卡……只是 URL 发生了变化……没有别的
标签: java selenium selenium-webdriver