1

I am trying to parse Upwork with Selenium and getting exception

Exception in thread "main" org.openqa.selenium.ElementNotVisibleException:

And I don't uderstand why. I try click on h2 element that contains link, on link itself, but get still same exception. I check styles of this element in development tools ant this element are visible.

I try use ExpectedConditions and wait until elements became visible, but get timeout exception. What did I do wrong and how I can click on this link?

Of course i can just use uri and open it, but i want solve problem with click.

System.setProperty("webdriver.gecko.driver", "/usr/local/bin/geckodriver");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.upwork.com/o/jobs/browse/");
List<WebElement> titles = driver.findElements(By.className("job-title"));
for (WebElement title: titles) {
    System.out.println("text: " + title.getAttribute("innerText"));
    System.out.println("tag: " + title.getTagName());
    title.click();
    driver.navigate().back();
}

1 Answer 1

1

I am not sure what exactly you are trying to do, however if you are trying to scrape the website, let me tell you this approach might not work. These websites are equipped with feature to identify bots, later or sooner it will identify your code and you will given captcha to verify.

But let's talk about your code, it's failing because the element is not visible. it's simple, could be because the visibility flag is false or size is not available or other reasons. simple fix is get the href element and your issue is solved.

Just add the TODO code and this code will be running.

    WebDriver driver = new FirefoxDriver();
    driver.get("https://www.upwork.com/o/jobs/browse/");
    List<WebElement> titles = driver.findElements(By.xpath("//h2/a"));
    for (int i=0; i<titles.size(); i++) {
        //TODO add a code to wait until first page loaded

        //To handle StaleElementReferenceException
        WebElement title = driver.findElements(By.xpath("//h2/a")).get(i);
        System.out.println("text: " + title.getAttribute("innerText"));
        System.out.println("tag: " + title.getTagName());
        title.click();
        driver.navigate().back();
    }
Sign up to request clarification or add additional context in comments.

3 Comments

I try just collect some statistics about most required jobs and most relevant for me.
@Hayate if it's working that good, what I am saying is if you will run in more frequently the captch will appear.
I understand, i add sound notification for case when captch appear, so i solve captch manualy when in required.

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.