2017-02-14 71 views
-3

嗨擴展後顯示國家代碼手機號碼格式時,我有combox。我打算自動化這個組合框。我嘗試使用Xpath,ID定位器,但無法選擇組合框。請讓我知道我沒有Webdriver:無法使用java選擇combox

<span class="select2-selection select2-selection--single" role="combobox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-labelledby="select2-mobile1-container"><span class="select2-selection__rendered" id="select2-mobile1-container"><span class="">Select</span></span><span class="select2-selection__arrow" role="presentation"><b role="presentation"></b></span></span>

+0

我想選擇這個下拉框的ID,但沒有運氣 – Aditya

+0

你是什麼意思'不能夠選擇組合框'?有什麼異常嗎?還分享你的嘗試代碼? –

+0

你能告訴我們你的代碼嗎? – Kenyanke

回答

0

您可以使用方法:

public void isChooseFromCombo(String text){       
String yourXpath="//*[contains(text),'"text"')]"; 
List<WebElement> element = 
getWebElement.findElement(By.xpath(yourXpath));    
    for(WebElement we : element){ 
    if(we.getText.contains(text)){ 
     we.click 
    } 
} 
+0

OK 007777ewq讓我試試,如有任何問題,我會盡快回復。 – Aditya

+0

沒有使用方法的其他方式? – Aditya

+0

它不工作?使用這種方法很簡單! – 007777ewq