无法从Naukri.com的下拉体验(Exp。)字段中选择值

时间:2013-12-27 19:01:19

标签: selenium

以下代码无效,并抛出如下所示的错误:

WebDriver driver=new FirefoxDriver();

driver.get("http://www.naukri.com/");

driver.manage().timeouts().implicitlyWait(100, TimeUnit.SECONDS);

Select Exp_drpdwn = new Select(driver.findElement(By.id("expSL")));

Exp_drpdwn.selectByValue("2"); 

错误

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 100.05 seconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'ANUPAM-PC', ip: '192.168.1.39', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
Session ID: 1c82f01f-2f60-43b6-8b70-ce139ee96508
Driver info: org.openqa.selenium.firefox.FirefoxDriver

1 个答案:

答案 0 :(得分:0)

您尝试选择的元素不可见。单击 By.id(" exp")节点后,可以看到它。因此,在访问选择之前,请尝试单击它:

driver.findElement(By.id("exp")).click();

或者,您可以使用JavaScript编辑值:

((JavascriptExecutor) driver).executeScript("document.getElementById('exp').value = 2");