I'm trying to make a code to get all the results from a specific search i do on a website.
Unfortunately, I haven't been able to print all the results from the classes i need.
Here is my code:
#Silent Display Settings display = Xvfb() display.start() #Login url = "https://www.foo.com" driver = webdriver.Chrome() #Submit Form if __name__ == "__main__": driver.get(url) select = Select(driver.find_element_by_id('test-make-box')) select.select_by_value('Test') driver.find_element_by_css_selector('.btn.btn-primary.btn--search').click() #Get info WebDriverWait(driver, 100).until( lambda driver: driver.find_element_by_class_name('listing-item__title')) XYZ # Here output results ... driver.quit() display.stop()
Here I need to print all values that come from two classes called listing-item__title
and listing-item__price
, how to do it?
-
Can you provide the print output and the original css to complete this question/answer? It isn't possible to learn from this question in the current incomplete form.EngineeringAsArt– EngineeringAsArt2019年11月21日 01:15:36 +00:00Commented Nov 21, 2019 at 1:15
1 Answer 1
You may wait for both the elements having listing-item__title
and listing-item__price
classes and then locate elements via .listing-item__title,.listing-item__price
CSS selector that would match both these types of elements:
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, 100)
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'listing-item__title')))
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'listing-item__price')))
for elm in driver.find_elements_by_css_selector(".listing-item__title,.listing-item__price"):
print(elm.text)
-
Thank you very much alecxe for your assistance. Now it works perfectlyuser1961382– user19613822017年06月20日 20:20:25 +00:00Commented Jun 20, 2017 at 20:20