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)")))
driver.find_element_by_css_selector()with providedCSSselector returns<div class="pg-loop">4</div>on pagination even without waiting. Can you share exception log or more details?