ショッピング用の 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 を使用しました。誰でもこの問題を解決するのを手伝ってくれますか?