Advertisement
Guest User

Untitled

a guest
May 24th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.support.wait import WebDriverWait
  3.  
  4. # create a new Firefox session
  5. driver = webdriver.Firefox()
  6. driver.implicitly_wait(30)
  7. driver.maximize_window()
  8.  
  9. # navigate to the application home page
  10. driver.get('http://magento.softwaretestingboard.com/')
  11.  
  12. # get the search textbox
  13. search_field = driver.find_element_by_name('q')
  14. search_field.clear()
  15. # enter search keyword and submit
  16. search_field.send_keys('t-shirt')
  17. search_field.submit()
  18.  
  19. #en = driver.find_element_by_id('search')
  20. #en.submit()
  21.  
  22. element = WebDriverWait(driver, 30).until(
  23. lambda x: x.find_elements_by_xpath("//p[@class='toolbar-amount']"))
  24.  
  25.  
  26. # get all the anchor elements which have product names displayed
  27. # currently on result page using find_elements_by_xpath method <li class="">
  28. products = driver.find_elements_by_xpath("//div[@class='product-item-info']")
  29.  
  30. # get the number of anchor elements found
  31. print('Found ' + str(len(products)) + ' products:')
  32.  
  33. # iterate through each anchor element and
  34. # print the text that is name of the product
  35. for product in products:
  36. print(product.text)
  37.  
  38. # close the browser window
  39. driver.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement