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.

2
  • Are you getting any errors? What is wrong with the code? Thanks. Commented Jun 19, 2017 at 18:55
  • yes the for loop is not working for me. so nothing is printing Commented Jun 19, 2017 at 19:03

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

8 Comments

Thankyou. Did the code work for you? I am still getting error in the loop with you code also
@Joe12 Yup, I have a working code. What error you are getting? Thanks.
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 ah, I had it too, solved by updating firefox and geckodriver to the latest versions.
@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.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.