0

I'm trying to access a select HTML element using Selenium WebDriver. But I'm getting a org.openqa.selenium.NoSuchElementException. This is happening only while handling elements inside a table. Otherwise elements are located easily.

Xpath I'm using:

Select URLSelect=new Select(driver.findElement(By.xpath("//table/tbody/tr/td[1]/select")));
URLSelect.selectByValue("Integration Console");

Screenshot of firepath console:

enter image description here

Console data:

org.openqa.selenium.NoSuchElementException: Unable to locate element: //table/tbody/tr/td[1]/select
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'D-113102687', ip: '10.200.214.51', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\KA318963\AppData\Local\Temp\rust_mozprofile.WRaqhIjIbR05, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0.2, platformVersion=10.0, moz:processID=11756.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt}]
Session ID: bcddd003-0d0a-43e6-8c10-98cbf91d5c43
*** Element info: {Using=xpath, value=//table/tbody/tr/td[1]/select}
    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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:410)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:509)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:402)
    at Trial.main(Trial.java:225)

Code:

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.support.ui.Select;
public class Trial {
public static void main(String[] args) throws ClassNotFoundException {

System.setProperty("webdriver.gecko.driver", "D:\\Selenium\\Gecko\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("SeleniumProfile");
WebDriver driver=new FirefoxDriver(myprofile);
driver.get("http://10.235.80.98:8080/digite/Request?Key=siteadm_login");
driver.findElement(By.xpath("//*[@id='loginId']")).sendKeys("admin");
driver.findElement(By.xpath("//*[@id='password']")).sendKeys("111111");
WebElement button=driver.findElement(By.xpath("html/body/div[1]/section/div/div/div/form/p[3]/input"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
            executor.executeScript("arguments[0].click();", button);
Thread.sleep(5000);
Select URLSelect=new Select(driver.findElement(By.id("selectURL")));
URLSelect.selectByValue("Integration Console");
Select jobSelect=new Select(driver.findElement(By.xpath("//*[@id='job']")));
jobSelect.selectByValue("Wipro Project Pre Process Adaptor");
driver.findElement(By.xpath("//*[@id='showSync_7004']")).click();
driver.quit();
} catch (Exception e) {
e.printStackTrace();
}
}
}

I have tried absolute xpath also for the same. But nothing I've tried seems to work. Help.

6
  • Does the exception happen when trying to find select Element or when selecting by Value ?
    – George
    Commented May 22, 2017 at 10:30
  • It happens when I try to find select element Commented May 22, 2017 at 10:48
  • Are you sure element is actually there when test tries to find it? What happens if you look up by Id instead of Xpath?
    – George
    Commented May 22, 2017 at 11:00
  • Yes I'm sure. It's a simple application. No dynamic content. The element is visible all the time. The same exception occurs when an ID is used as well. Commented May 22, 2017 at 11:27
  • If its there when driver tries to find it, and the id or xpath is correct, there would be no exception, maybe you can post some code leading up to findElement
    – George
    Commented May 22, 2017 at 11:51

1 Answer 1

1

I would suggest you wait for the webelement to get loaded first then perform the activity that you want to do.

//Initialize a wait for 30 seconds.
WebDriverWait wait = new WebDriverWait(driver,30)

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("selectURL"))); /*Waiting for the WebElement to be Visible.*/

Select URLSelect=new Select(driver.findElement(By.id("selectURL")));
URLSelect.selectByValue("Integration Console");
1
  • Still won't work. Commented May 23, 2017 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.