2 回答
TA贡献1895条经验 获得超3个赞
以下是在单击“提交”之前和单击“提交”之后必须使用的代码行。然后比较它们不匹配。
driver.findElement(By.xpath("//span[@class='et_pb_contact_captcha_question']")).getText();
TA贡献1860条经验 获得超8个赞
我在上面添加了这个代码,并添加了比较方法。你能不能看看这没问题?
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.");
}
}
添加回答
举报