java - Selenium - 如何确认提交后更改了带有两个数字的验证码
问题描述
我试图找到有关我的问题的任何帮助,但没有成功。我需要确认验证码(两个数字)在无效提交后被更改。两个数字位于 span 标签中(您可以打开此 URL 并查看https://www.ultimateqa.com/filling-out-forms/)。
脚步:
- 打开https://www.ultimateqa.com/filling-out-forms/
- 填写右边的表格,但故意输入-1作为加法的结果
- 提交表格并确认数字已更改
我解决了前两个步骤,但我用第三步阻止了。有人可以帮我解决这个问题吗?
package zadaci;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class zadatak1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "D:\\DriversSelenium\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.ultimateqa.com/filling-out-forms/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"et_pb_contact_name_1\"]")).sendKeys("TestName");
driver.findElement(By.xpath("//*[@id=\"et_pb_contact_message_1\"]")).sendKeys("TestMessage");
driver.findElement(By.xpath("/html/body/div[1]/div/div/article/div/div[1]/div/div/div/div[2]/div/div[2]/form/div/div/p/input")).sendKeys("-1");
driver.findElement(By.xpath("/html/body/div[1]/div/div/article/div/div[1]/div/div/div/div[2]/div/div[2]/form/div/button")).click();
driver.findElement(By.xpath("/html/body/div[1]/div/div/article/div/div[1]/div/div/div/div[2]/div/div[2]/form/div/div/p/span")).getText();
driver.close();
System.out.println("Test script executed successfully.");
}
}
提前致谢。:)
解决方案
我在上面添加了这段代码并添加了比较方法。如果可以,请您看看好吗?
package zadaci;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class zadatak1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "D:\\DriversSelenium\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://www.ultimateqa.com/filling-out-forms/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id=\"et_pb_contact_name_1\"]")).sendKeys("TestName");
driver.findElement(By.xpath("//*[@id=\"et_pb_contact_message_1\"]")).sendKeys("TestMessage");
driver.findElement(By.xpath("/html/body/div[1]/div/div/article/div/div[1]/div/div/div/div[2]/div/div[2]/form/div/div/p/input")).sendKeys("-1");
driver.findElement(By.xpath("//span[@class='et_pb_contact_captcha_question']")).getText();
driver.findElement(By.xpath("/html/body/div[1]/div/div/article/div/div[1]/div/div/div/div[2]/div/div[2]/form/div/button")).click();
driver.findElement(By.xpath("//span[@class='et_pb_contact_captcha_question']")).getText();
if("expected String".equals("actual string"))
{
System.out.println("Numbers are the same! ");
}
else
{
System.out.println("Numbers are changed! ");
}
driver.close();
System.out.println("Test script executed successfully.");
}
}
谢谢
推荐阅读
- dax - 如何修改 DAX ALLEXCEPT 以允许过滤
- reactjs - Reactjs条件渲染问题
- html - div 内的视频背景和文本不会随着页面的其余部分滚动?
- flutter - 将 camera_platform_interface 从 1.0.4 升级到 1.2.0 导致相机无法工作
- sql - SELECT 语句中的表达式
- python - python if 语句无法与 gensim 语言模型一起正常工作
- php - WordPress Woocommerce Limited by PHP-FPM Processes Ram Utilization 的最大用户数
- python - 中断线程中的无限循环
- python - 请求的 URL 不允许该方法:使用 Flask POST 方法
- javascript - 在功能组件中使用方法回调测试按钮