3

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?

alecxe
11.4k11 gold badges52 silver badges107 bronze badges
asked Jun 19, 2017 at 21:35
1
  • 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. Commented Nov 21, 2019 at 1:15

1 Answer 1

2

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)
answered Jun 19, 2017 at 22:18
1
  • Thank you very much alecxe for your assistance. Now it works perfectly Commented Jun 20, 2017 at 20:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.