第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何使用 Selenium 和 Java 通過(guò) sendKeys 方法傳遞雙引號(hào)字符串

如何使用 Selenium 和 Java 通過(guò) sendKeys 方法傳遞雙引號(hào)字符串

慕仙森 2023-07-28 16:46:06
我正在編寫(xiě)一個(gè) selenium 腳本,其中正在獲取 3 個(gè)值并將其存儲(chǔ)在 String 中。String one = "19292";String two = "Abc";String three = "def";我希望它以(一+二+三)的形式發(fā)送文本,但它們都帶有雙引號(hào)。所以最終結(jié)果應(yīng)該是"19292""Abc""def"我怎樣才能做到這一點(diǎn) ?我嘗試過(guò)使用反斜杠來(lái)使用轉(zhuǎn)義機(jī)制,但是每當(dāng)我使用它而不是獲取字符串值時(shí),它都會(huì)打印文本。對(duì)于例如:\"one\" prints "one" rather than "19292"
查看完整描述

4 回答

?
皈依舞

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超3個(gè)贊

嘗試這樣:


field.sendKeys("\"" + one + "\"\"" + two + "\"\"" + three + "\"");

我剛剛檢查了硒,它有效。進(jìn)入字段的輸入是:“19292”“Abc”“def”


或者,如果您不知道字符串的數(shù)量,那么下面是將轉(zhuǎn)換為引號(hào)格式的方法。


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();

}


查看完整回答
反對(duì) 回復(fù) 2023-07-28
?
江戶川亂折騰

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊

嘗試:

String str = "\""+one+"\"\""+two+"\"\""+three+"\"";
System.out.println(str);

這將打印"19292""Abc""def"


查看完整回答
反對(duì) 回復(fù) 2023-07-28
?
小唯快跑啊

TA貢獻(xiàn)1863條經(jīng)驗(yàn) 獲得超2個(gè)贊

如果您的用例是將結(jié)果字符串作為 傳遞"19292" "Abc" "def",那么以下Strings聲明肯定不會(huì)幫助達(dá)到目的:


String one = "19292";

String two = "Abc";

String three = "def";

相反,您需要執(zhí)行以下操作:


String one = " \"19292\" ";

String two = " \"Abc\" ";

String three = " \"def\" ";

使用Google 主頁(yè)的文本框"19292" "Abc" "def"將字符串作為 ** **發(fā)送的示例,您可以使用以下定位器策略:

代碼塊:


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);

? ? }

}

瀏覽器快照:

https://img2.sycdn.imooc.com/64c380910001f35313660767.jpg

查看完整回答
反對(duì) 回復(fù) 2023-07-28
?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗(yàn) 獲得超9個(gè)贊

嘗試這個(gè):

String text = "\"" + one + "\"\"" + two + "\"\"" + three + "\"";


查看完整回答
反對(duì) 回復(fù) 2023-07-28
  • 4 回答
  • 0 關(guān)注
  • 257 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)