WebDriver 및 selenium-firefox-driver 버전 2.3.1을 사용하고 있습니다. option.setSelected();
이되지 않는 경우 이제, 하나는 직접 또는 더 정확히 option.click();
을 수행해야합니다WebDriver의 옵션 선택
if (value.equals(option.getAttribute("value"))) {
if(!option.isSelected()) {
option.click();
break;
}
}
문제는 내가 이유없이이 예외를 얻을 것이다.
요소가 현재 표시되지 않는 등 또한
<select id="deadLineDay" name="deadLineDay">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
과 상호 작용 할 수 없습니다, 그것은 타이밍 문제 ...는 도대체 무엇인지 어떤 생각을 확실히하지? 예외는 가끔 발생하지만, 내가 말한대로,하지 타이밍 문제, 내가
이것은 코드 디버깅 해요 :
public FillOutForm(WebDriver driver, UploadDocumentPage parent) {
this.driver = driver;
this.parent = parent;
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 3), this);
}
@FindBy(how = How.NAME, using = day)
private WebElement deadLineDay;
@CacheLookup
@FindBy(how = How.NAME, using = hour)
private WebElement deadLineHour;
@CacheLookup
@FindBy(how = How.NAME, using = minute)
private WebElement deadLineMinute;
@CacheLookup
@FindBy(how = How.NAME, using = AmPm)
private WebElement deadLineAmPm;
@CacheLookup
@FindBy(how = How.ID, using = desc)
private WebElement description;
@CacheLookup
@FindBy(how = How.ID, using = comm)
private WebElement comment;
public boolean validationPasses(Map<String, String> map) {
try {
for (String key : map.keySet()) {
WebElement we = (WebElement) this.getClass().getDeclaredField(key).get(this);
setSelectedField(we, map.get(key));
}
} catch (Exception e) {
throw new Error(e.getMessage());
}
valid = elementExists(driver, By.className(validatorError));
return valid;
}
public void setSelectedField(WebElement element, String value) {
List<WebElement> options = element.findElements(By.tagName("option"));
for (WebElement option : options) {
if (value.equals(option.getAttribute("value"))) {
if(!option.isSelected()) {
option.click();
break;
}
}
}
}
아마도 당신은 내가 그것이 문제가되지했다 요소 (제대로로드) –
기다릴 org.openqa.selenium.support.ui.WebDriverWait를 구현해야 .. 이미 시도했습니다 – lisak
그것은 선택 필드에 도착하기 전에 해당 페이지에서 10 개의 다른 필드를 처리합니다. 필드가로드 될 때까지 3 초를 기다리고 있습니다 ... 전에 1 초였습니다 ... PageFactory.initElements (new AjaxElementLocatorFactory (driver, 3), this); – lisak