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);
}
}
浏览器快照:
添加回答
举报