如何使用 Selenium 中的操作將字母大寫後輸入到編輯框?
藉助操作,我們可以在 Selenium 中以大寫形式將字母輸入到編輯框中。為了實現此目的,我們首先需要移動到編輯框中,然後單擊該欄位。然後按 SHIFT 並使用 sendKeys() 方法輸入字母。最後,使用 build().perform() 執行所有步驟。
示例
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 org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import java.util.concurrent.TimeUnit;
public class UpperCase{
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String url = "https://tutorialspoint.tw/questions/index.php";
driver.get(url);
driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
// move to the element, press shift and then enter the letters then //perform() to execute the action
Actions a = new Actions(driver);
a.moveToElement(driver.findElement(By.xpath(“input[@type=’text’]))).
click().keyDown(Keys.SHIFT).sendKeys(“tutorialspoint”).
build().perform();
driver.quit();
}
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP