1

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?

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 perfectly – user1961382 Jun 20 '17 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.