4 回答

TA貢獻1851條經驗 獲得超3個贊
嘗試這樣:
field.sendKeys("\"" + one + "\"\"" + two + "\"\"" + three + "\"");
我剛剛檢查了硒,它有效。進入字段的輸入是:“19292”“Abc”“def”
或者,如果您不知道字符串的數量,那么下面是將轉換為引號格式的方法。
public static void main(String[] args) {
String one = "19292";
String two = "Abc";
String three = "def";
System.out.println(surroundWithDoubleQuotes(one, two, three));
}
public static String surroundWithDoubleQuotes(String... input) {
if(input == null || input.length == 0) {
return "";
}
StringBuilder builder = new StringBuilder();
for(String arg : input) {
builder.append("\"\"");
builder.append(arg);
}
builder.append("\"");
builder.deleteCharAt(0);
return builder.toString();
}

TA貢獻1851條經驗 獲得超5個贊
嘗試:
String str = "\""+one+"\"\""+two+"\"\""+three+"\""; System.out.println(str);
這將打印"19292""Abc""def"

TA貢獻1863條經驗 獲得超2個贊
如果您的用例是將結果字符串作為 傳遞"19292" "Abc" "def",那么以下Strings聲明肯定不會幫助達到目的:
String one = "19292";
String two = "Abc";
String three = "def";
相反,您需要執行以下操作:
String one = " \"19292\" ";
String two = " \"Abc\" ";
String three = " \"def\" ";
使用Google 主頁的文本框"19292" "Abc" "def"
將字符串作為 ** **發送的示例,您可以使用以下定位器策略:
代碼塊:
public class A_demo?
{
? ? public static void main(String[] args) throws Exception?
? ? {
? ? ? ? String one = " \"19292\" ";
? ? ? ? String two = " \"Abc\" ";
? ? ? ? String three = " \"def\" ";
? ? ? ? System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
? ? ? ? ChromeOptions options = new ChromeOptions();
? ? ? ? options.addArguments("start-maximized");
? ? ? ? options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
? ? ? ? options.setExperimentalOption("useAutomationExtension", false);
? ? ? ? WebDriver driver = new ChromeDriver(options);
? ? ? ? driver.get("https://www.google.com/");
? ? ? ? new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.name("q"))).sendKeys(one + two + three);
? ? }
}
瀏覽器快照:
添加回答
舉報