Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 硒-如何确认提交后更改了两个数字的验证码_Java_Eclipse_Selenium_Selenium Webdriver - Fatal编程技术网

Java 硒-如何确认提交后更改了两个数字的验证码

Java 硒-如何确认提交后更改了两个数字的验证码,java,eclipse,selenium,selenium-webdriver,Java,Eclipse,Selenium,Selenium Webdriver,我试图就我的问题寻求任何帮助,但没有成功。我需要确认,无效提交后,验证码两个数字被更改。两个数字位于span标记中,您可以打开此URL并查看 步骤: 打开 填写右边的表格,但故意输入-1作为添加的结果 提交表格并确认编号已更改 我解决了前两个步骤,但我用第三个步骤阻止了。有人能帮我解决这个问题吗 package zadaci; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.open

我试图就我的问题寻求任何帮助,但没有成功。我需要确认,无效提交后,验证码两个数字被更改。两个数字位于span标记中,您可以打开此URL并查看

步骤:

打开 填写右边的表格,但故意输入-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.");

    }

}

提前谢谢

这是您在单击提交之前和之后必须使用的代码行。然后比较它们是否不匹配

driver.findElement(By.xpath("//span[@class='et_pb_contact_captcha_question']")).getText();

我在上面添加了这段代码,并添加了比较方法。你能看看这是否合适吗

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.");

    }


    }
谢谢你

你的问题必须包括到目前为止你为解决问题所做工作的总结,以及你解决问题的困难的描述。