2011-02-01 11 views

cevap

29

gezebilir ve HtmlSelect kullanarak sayfa <select> elemanları işleyebilirsiniz:

WebClient client = ... 
Page page = client.getPage(url); 
HtmlSelect select = (HtmlSelect) page.getElementById(mySelectId); 
HtmlOption option = select.getOptionByValue(desiredOptionValue); 
select.setSelectedAttribute(option, true); 

JavaDoc bu gibi şeyler yapmak için esnek bir API yöntemlerinin bir sürü olduğunu göstermektedir.

1

takiben kodu:

HtmlSelect select = page.getElementById(mySelectId); 

olmalıdır:

HtmlSelect select = (HtmlSelect)page.getElementById(mySelectId); 
1

ekle follwoing hatları:

protected void selectOption(WebElement el, String option) 
{ 
    Select select = new Select(el); 
    select.selectByVisibleText(option); 
} 

protected WebElement elById(String id) 
{ 
    return driver.findElement(By.id(id)); 
} 

// "title" is your drop-down HTML id 
public void populateForm(String elValue) 
{ 
    selectOption(elById("title"), elValue); 
} 
İlgili konular