Reputation: 35
I am running into an issue where I cannot select the correct CSS selector. I think the website itself is causing the issue. Any ideas why it isn't selecting correctly?
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import requests, time
driver = webdriver.Firefox(executable_path="geckodriver")
driver.get("https://www.okcc.online/")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='rod-menu-button']"))).click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='rodDocTypeTxt']"))).send_keys('MTG')
wait.until(EC.element_to_be_clickable((By.XPATH, "//ul[@id='ui-id-1']//li//div"))).click()
driver.find_element_by_xpath('//*[@id="rod-date-toggle"]').click()
driver.find_element_by_xpath('//*[@id="rodFromDateTxt"]').send_keys('4/1/2020')
driver.find_element_by_xpath('//*[@id="rodToDateTxt"]').send_keys('4/20/2020')
search_button = driver.find_element_by_xpath('//*[@id="rod-submit-search"]').click()
time.sleep(2)
pdf = driver.find_elements_by_css_selector("icon pdf-icon")
print(len(pdf))
When I run this, it returns a count of 0, where it should return a count of 50 if I am selecting the CSS correctly on this site.
Ultimately I want to iterate through all of these items, and download the pdf that returns..but I cannot even get the dang thing to be recognized.
Upvotes: 0
Views: 119
Reputation: 416
Try div.icon.pdf-icon
.
That is what is suggested here: Locating Elements
Upvotes: 0
Reputation: 649
This will select all elements with compound class icon pdf-icon
driver.find_elements_by_css_selector(".icon.pdf-icon")
This will select all div tags with compound class icon pdf-icon
driver.find_elements_by_css_selector("div.icon.pdf-icon")
More information about css selectors https://www.w3schools.com/cssref/css_selectors.asp
Upvotes: 1