如何在 Selenium 中提交表單?
我們可以透過以下方法在 Selenium 中提交表單 −
submit()
click()
使用 submit() 方法的程式碼實現。
示例
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class SubmitScripting {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "<<web url with a form submit feature>>";
driver.get(url);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// submit method to submit the form
driver.findElement(By.id("<<id expression>>")).submit();
driver.close();
}
}使用 click() 方法的程式碼實現。
示例
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
public class ClickScripting {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "<<web url with a form submit feature>>"; driver.get(url);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// click method to submit the form
driver.findElement(By.id("<<id expression>>")).click();
driver.close();
}
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP