如何使用 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.com/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