1
WebDriver driver = new FirefoxDriver();
driver.get("https://www.ignitionone.com/company/careers/");
driver.manage().window().maximize();

Thread.sleep(2000);

driver.findElement(By.cssSelector("button.teal")).click();      

Thread.sleep(2000);
String s2 =driver.findElement(By.cssSelector("#board_title")).getText();

List<WebElement>d_details = driver.findElements(By.cssSelector(".level-0"));
    for(int i=0; i<d_details.size();i++){
    WebElement element = d_details.listIterator();
    String innerhtml = element.getAttribute("innerHTML");

    System.out.println("Available openings  are" + innerhtml);
}


System.out.println("The title is " + s2);

driver.quit();

This is my code.I am trying to print the available job openings in different areas in the webpage. Can someone please help to understand whats going wring in here.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Joe12
  • 69
  • 1
  • 12

1 Answers1

3

You have a type casting problem on this line:

WebElement element = d_details.listIterator();

A better way to iterate over the elements would be this:

List<WebElement> results = driver.findElements(By.cssSelector(".level-0"));
for (WebElement result: results) {
    String innerhtml = result.getAttribute("innerHTML");
    System.out.println("Available openings  are" + innerhtml);
}

Note that you may also be experiencing a timing issue. You should replace your Thread.sleep() calls with Explicit Wait commands, check out this topic:

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thankyou. Did the code work for you? I am still getting error in the loop with you code also – Joe12 Jun 19 '17 at 20:02
  • @Joe12 Yup, I have a working code. What error you are getting? Thanks. – alecxe Jun 19 '17 at 20:03
  • Exception in thread "main" org.openqa.selenium.WebDriverException: Permission denied to access property "_wrapped" Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, appBuildId=20161019084923, version=49.0.2, platform=XP, proxy=Proxy(), command_id=1.0, specificationLevel=0.0, acceptSslCerts=false, processId=10516.0, browserVersion=49.0.2, platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, javascriptEnabled=true, platformName=win – Joe12 Jun 19 '17 at 20:08
  • @Joe12 ah, I had it too, solved by updating firefox and geckodriver to the latest versions. – alecxe Jun 19 '17 at 20:09
  • whats your current version of both – Joe12 Jun 19 '17 at 20:10
  • @Joe12 firefox 54, geckodriver 0.17. – alecxe Jun 19 '17 at 20:11
  • That worked . this is the result i am gettting.But how do i get only 'customer service europe', 'project manger', 'location from this

    Customer Success Europe

    Project Manager
    Brussels
    – Joe12 Jun 19 '17 at 20:29
  • 1
    @Joe12 If the answer has solved your problem, kindly mark it as the accepted answer. If you encounter a new problem or if you have a new question, please consider opening a new topic instead. – iamkenos Jun 20 '17 at 02:18