Reputation: 33
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
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
Upvotes: 0
Views: 167
Reputation: 473753
The selector itself is too fragile because:
col-xs-12
that are usually too broad and have a higher chance to be changedInstead, 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)")))
Upvotes: 1