我试图找到有关我的问题的任何帮助,但未成功。无效提交后,我需要确认验证码(两个数字)是否已更改。 span标签中有两个数字(您可以打开此URL并查看https://www.ultimateqa.com/filling-out-forms/)。
步骤:
我解决了前两个步骤,但在第3个步骤中被阻止。有人可以帮我解决这个问题吗?
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.");
}
}
先谢谢了。 :)
答案 0 :(得分:0)
这是您在单击提交之前和单击提交之后必须使用的代码行。然后比较它们不匹配。
driver.findElement(By.xpath("//span[@class='et_pb_contact_captcha_question']")).getText();
答案 1 :(得分:0)
我在上面添加了此代码并添加了compare方法。可以吗?
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.");
}
}
谢谢