我正在自动化一个用于购物的 Web 应用程序。在特定页面中,我必须通过单击提交按钮来提交。我在 selenium web 驱动程序中编写代码以实现同样的事情。单击了该按钮,但它从未导航到下一页,也没有抛出任何异常,我可以看到测试成功运行。
package org.karmaloop.testcase;
import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.karmaloop.configuration.Testconfiguration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
@RunWith(BlockJUnit4ClassRunner.class)
public class testcase1 {
private static ChromeDriverService srv;
private WebDriver driver;
@BeforeClass
public static void StartServer() throws IOException {
// Below file path to Chrome browser should be changed accordingly
srv = new ChromeDriverService.Builder()
.usingDriverExecutable(
new File("D:\\chromedriver\\chromedriver.exe"))
.usingAnyFreePort().build();
srv.start();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before()
public void setUp() throws Exception {
driver = new RemoteWebDriver(srv.getUrl(), DesiredCapabilities.chrome());
}
@After
public void tearDown() throws Exception {
}
@Test
public void test() throws Exception {
Normal_Checkout();
}
private void Normal_Checkout() throws Exception {
//To get commented
driver.get("https://m.karmaloop.com/product/The-Superstar-80s-GRF-Sneaker-in-Wheat-Black-Chalk/384883");
driver.findElement(By.cssSelector(Testconfiguration.size_dropdown)).click();
System.out.println("success");
Thread.sleep(4000);
driver.findElement(By.xpath(Testconfiguration.select_size)).click();
Thread.sleep(4000);
driver.findElement(By.xpath(Testconfiguration.addtocart_button)).click();
Thread.sleep(7000);
driver.findElement(By.xpath(Testconfiguration.pcheckout_button)).click();
Thread.sleep(5000);
// To get commented
driver.findElement(By.xpath(Testconfiguration.checkout_logintxtbox)).sendKeys(Testconfiguration.checkout_login_username);
Thread.sleep(5000);
driver.findElement(By.xpath(Testconfiguration.checkout_passwordtxtbox)).sendKeys(Testconfiguration.checkout_login_password);
Thread.sleep(5000);
driver.findElement(By.xpath(Testconfiguration.checkout_loginbtn)).click();
Thread.sleep(10000);
System.out.println("Passed before checkout");
driver.findElement(By.xpath(Testconfiguration.submit_button));
Thread.sleep(20000);
System.out.println("submit clicked");
}}
==================================================== =================================我已经使用xpath来提交按钮被点击。谁能帮我解决这个问题。