0

i got a css-selector that reads

#block-a4e7-et-lists-a4e7-et-lists-content > div > div > div.row > div.col-md-9.col-sm-12.col-lg-9.col-xs-12 > div > div.a4e7-fw-pagination > div:nth-child(5)

on the webpage

http://www.ecotechnology.at/de/content/ausbildung-weiterbildung-und-gr%C3%BCne-stellenangebote?etsv=karriere_at

but even after long struggle i do not manage to access it with selenium's driver.find_element_by_css_selector() function in python.

could you help me with this?

best anda

4
  • Do you want to use xpath or css-selector only? Commented May 10, 2017 at 9:49
  • what is that you are trying to access. please be descriptive Commented May 10, 2017 at 9:49
  • Please show your code, the expected response and the actual response. Commented May 10, 2017 at 9:51
  • driver.find_element_by_css_selector() with provided CSS selector returns <div class="pg-loop">4</div> on pagination even without waiting. Can you share exception log or more details? Commented May 10, 2017 at 10:01

1 Answer 1

1

The selector itself is too fragile because:

  • it heavily relies on direct parent-child relationship and hence the structure of the page
  • it uses layout-oriented classes like col-xs-12 that are usually too broad and have a higher chance to be changed

Instead, I'd use the following CSS selector:

.content .a4e7-fw-pagination > div:nth-child(5)

You might also be experiencing a timing problem - the element is not yet present when you search for it. The common way to tackle problems like this is an Explicit Wait. To be specific, in your case, you might have something like:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".content .a4e7-fw-pagination > div:nth-child(5)")))
Sign up to request clarification or add additional context in comments.

1 Comment

alecxe, many thanks for your very helpful comment and the associated explanation. that's what i've been looking for. thanks also to the others for their efforts.

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.