Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. for link in dom.xpath('//div[@id="right-column"]//a/@href'):
  2. FINAL_URL = urlparse.urljoin(url, link)
  3.  
  4. my_page = '//div[@class="product_info"]//table//tr[7]//td[2]//a/@href'
  5.  
  6. for link1 in dom1.xpath(my_page):
  7. # more code to go
  8.  
  9. for link1 in dom1.xpath(my_page):
  10. if link1[:4] == 'http':
  11. driver.get(link1)
  12. inputElement = driver.find_element_by_xpath("//input​[@*[contains(., 'name')]]")
  13. inputElement.send_keys("somename")
  14. inputElement1 = driver.find_element_by_xpath("//input​[@*[contains(., 'email')]]")
  15. inputElement1.send_keys("email@yahoo.com")
  16. inputElement1.send_keys(Keys.ENTER)
  17. assert "No results found." not in driver.page_source
  18.  
  19. line 38, in <module>
  20. inputElement = driver.find_element(By.XPATH, "//input​[@*[contains(., 'name')]]")
  21. File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 707, in find_element
  22. {'using': by, 'value': value})['value']
  23. selenium.common.exceptions.InvalidSelectorException
  24.  
  25. # -*- coding: utf-8 -*-
  26.  
  27. import urlparse
  28. import lxml.html
  29.  
  30.  
  31.  
  32. from selenium import webdriver
  33. from selenium.webdriver.common.keys import Keys
  34.  
  35. from pyvirtualdisplay import Display
  36.  
  37. display = Display(visible=0, size=(800, 600))
  38. display.start()
  39.  
  40. driver = webdriver.Firefox()
  41.  
  42.  
  43. URL = 'http://example.com'
  44. dom = lxml.html.parse(URL)
  45. url = dom.docinfo.URL
  46. BASE = dom.find('head/base')
  47. EMPTY = ''
  48.  
  49. if BASE:
  50. url = BASE.get('href', url)
  51.  
  52. for link in dom.xpath('//div[@id="right-column"]//a/@href'):
  53. FINAL_URL = urlparse.urljoin(url, link)
  54.  
  55. dom1 = lxml.html.parse(FINAL_URL)
  56. my_page = '//div[@class="product_info"]//table//tr[7]//td[2]//a/@href'
  57.  
  58. for link1 in dom1.xpath(my_page):
  59. if link1[:4] == 'http':
  60. driver.get(link1)
  61. inputElement = driver.find_element_by_xpath("//input​[@*[contains(., 'name')]]")
  62. inputElement.send_keys("cevanume")
  63. inputElement1 = driver.find_element_by_xpath("//input​[@*[contains(., 'email')]]")
  64. inputElement1.send_keys("email@yahoo.com")
  65. inputElement1.send_keys(Keys.ENTER)
  66. assert "No results found." not in driver.page_source
  67.  
  68. driver.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement