I want to search specific word in ScienceDirect and when is shows results I want to click 100 result per page at the bottom on page.
HTML code:
<a data-aa-region="srp-pagination-options" data-aa-name="srp-100-results-per-page" href="/search?qs=Python&show=100"><span >100</span></a>
And that's my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("https://www.sciencedirect.com/")
assert "Science" in driver.title
elem = driver.find_element(By.ID, "qs-searchbox-input")
elem.clear()
elem.send_keys("Python")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, ".data-aa-name[value='srp-100-results-per-page']"))
)
element.click()
driver.close()
And exception:
Traceback (most recent call last):
File "X:\pythonProject\selenium\count_cited.py", line 15, in <module>
element = WebDriverWait(driver, 10).until(
File "X:\pythonProject\selenium\venv\lib\site-packages\selenium\webdriver\support\wait.py", line 95, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
CodePudding user response:
Use for example this CSS selector:
"div#srp-pagination-options li:nth-child(3)"