When i am type casting from webelement type to string Type i am getting the below error.
Exception in thread "main" java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to java.lang.String
at JavaSelenium.TestSelenium.testObj.main(testObj.java:45)
package JavaSelenium.TestSelenium;
import java.util.Iterator;
import java.util.List;
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 testObj {
public static void main(String args[]) throws InterruptedException {
// ProfilesIni Prof = new ProfilesIni();
// FirefoxProfile pro = Prof.getProfile("Selenium");
// WebDriver driver = new FirefoxDriver(pro);
WebDriver driver = new FirefoxDriver();
Thread.sleep(6000);
driver.manage().window().maximize();
WebElement element = driver.findElement(By.id("DDSrchPropertyType"));
Select select= new Select(element);
List<WebElement> options = select.getOptions();
Iterator it= options.iterator();
String Str;
while (it.hasNext()) {
Str = (String) it.next(); // unable to typecast
System.out.println(it.next());
}
driver.close();
}
}
Please let me know how to resolve this issue.