Question

I was trying to automate the Reset functionality in "http://www.efrotech.com/careers" for learning purposes. When I get the control locators I see it is perfect HTML that has almost all the locators; but when I try to run the script it is not recognizing the control and throwing painful NoSuchElement exception. Can you suggest what could be going wrong in that?

    package com;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class ScriptChecker {

    /**
     * @param args
     */

    public static WebDriver driver;
    public static String baseUrl;

    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub

        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        baseUrl = "http://www.efrotech.com";


        driver.get(baseUrl +"/careers");


        new Select(driver.findElement(By.id("ddlJobs"))).selectByVisibleText("QA Engineer");
        driver.findElement(By.cssSelector("input#txtName")).sendKeys("Muzaffar");

        System.out.println("Done here");

    }

}

I have tried every locator but unable to manipulate the control state and its values.

Stacktrace followed:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"ddlJobs"} Command duration or timeout: 10.07 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32' System info: host: 'muzaffar', ip: '192.168.0.161', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_05' Session ID: 206431fe-6770-4cbc-a60e-71fe92739807 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, browserName=firefox, rotatable=false, locationContextEnabled=true, version=25.0.1, cssSelectorsEnabled=true, databaseEnabled=true, handlesAlerts=true, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, applicationCacheEnabled=true, takesScreenshot=true}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348) at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:389) at org.openqa.selenium.By$ById.findElement(By.java:214) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340) at com.ScriptChecker.main(ScriptChecker.java:30) Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"id","selector":"ddlJobs"} Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:17:32' System info: host: 'muzaffar', ip: '192.168.0.161', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_05' Driver info: driver.version: unknown at .FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/SMUZAF~1/AppData/Local/Temp/anonymous1906408348495286600webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:8905) at .fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/SMUZAF~1/AppData/Local/Temp/anonymous1906408348495286600webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:396)

Was it helpful?

Solution

The drop down element which you are trying to use is under iFrames. Please switch to it and then proceed with your selection.

driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[height='520']")));
new Select(driver.findElement(By.xpath(".//*[@id='ddlJobs']"))).selectByVisibleText("QA Engineer");

hope this solves.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top