0

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.

1
  • Do you need to preface the selector with a '.' so pdf = driver.find_elements_by_css_selector(".icon.pdf-icon") as per documentation seleniumeasy.com/selenium-tutorials/… Commented Apr 20, 2020 at 23:07

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Please explain what the difference is and why this one works.
0

Try div.icon.pdf-icon. That is what is suggested here: Locating Elements

Comments

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.