2016-05-16 64 views
0

在我的情况下,一个页面包含下拉控件。这实际上是Html代码的输入标签,使用ExtJs它的值可以被设置。 现在我试图使用webDriver自动化这个控制值选择。以下是我的脚本执行此代码。控制的默认值是'Equal'。DropDown selected在浏览器中不可见的值

Here is my Html code and control

现在我试图使用自动化webdriver的这个控制值的选择。以下是我使用的脚本。

@Test(priority=4, dependsOnMethods = {"GoToAssesssmentMetaDataSearch"},alwaysRun = true) 
public void SelectSearchCriteriaAssesssmentMetaDataSearch(){ 
     mDriver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);  
     JavascriptExecutor jse = (JavascriptExecutor)mDriver; 
     ((JavascriptExecutor)mDriver).executeAsyncScript("jQuery('.x-form-field.x-form-text.x-form-text-default.x-form-focus.x-field-form-focus.x-field-default-form-focus').val('In');"); 
     mDriver.manage().timeouts().setScriptTimeout(15, TimeUnit.SECONDS); 
} 

这个脚本成功运行和测试得到passed.But在GUI窗口(IntPut标签)不显示,设置运行时间在剧本即“在”在这种情况下,实际值。当我在WenDriver Browser实例的控制台窗口中查看相同的jQuery命令时,它显示选定的值。 任何人都可以告诉我我错在哪里。

回答

0

试试这个:

WebElement element = (new WebDriverWait(driver, 10)) 
    .until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#combobox-2006-bodyE1"))); 
driver.findElement(By.cssSelector("input#combobox-2006-inputE1")).sendKeys("In"); 

让我知道,如果这有助于..

注意前给予一定的等待时间,并确保元素存在

+0

不工作,它显示异常“元素应该”选择“但是被输入”。这是因为我的实际Web控件是INPUT标签,而Select是用于DropDown的。 – Ishekh

+0

我会更新答案 –

+0

更新我的答案..检查是否有帮助 –

0

请使用

Select obj = new Select(driver.findElement(By.id("comobobox-2006-inputE!"))); 
  1. obj.selectByVisibleText("EQUALS");
  2. obj.selectByIndex(0);
  3. obj.selectByValue("eq");

选择任何&让我知道,如果这可以帮助您。 如果通过ID查找对您没有帮助,则更改查找元素定位器选择选项。使用xpath而不是id。

+0

不工作。也可以尝试使用其他的id,xpath和cssselector选项。但没有运气。 – Ishekh

相关问题