Advertisement
Guest User

Untitled

a guest
Apr 17th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. import time
  2. import pyscreenshot as ImageGrab
  3. from selenium import webdriver
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.common.keys import Keys
  6. from selenium.webdriver.support.wait import WebDriverWait
  7. from selenium.webdriver.support import expected_conditions as EC
  8. from selenium.webdriver.common.action_chains import ActionChains
  9. import webbrowser
  10. #import urllib2
  11.  
  12.  
  13. URL = "http://vps17154.inmotionhosting.com/~heathtilevb/"
  14. #EMAIL = 'your email here'
  15. #PASSWORD = 'your password here'
  16.  
  17. driver = webdriver.Chrome('/usr/local/chromedriver') # can be webdriver.Firefox() in your case
  18. driver.get(URL)
  19. #html_content = urllib2.urlopen('http://vps17154.inmotionhosting.com/~heathtilevb')
  20. wait = WebDriverWait(driver, 10)
  21.  
  22. # login
  23. #form = driver.find_element_by_class_name('regular_login')
  24. #username = form.find_element_by_name('email')
  25. #username.send_keys(EMAIL)
  26.  
  27. #password = form.find_element_by_name('password')
  28. #password.send_keys(PASSWORD)
  29.  
  30. #login_button = form.find_element_by_xpath('//input[@type="submit" and @value="Login"]')
  31. #login_button.click()
  32.  
  33. # search
  34. #search = wait.until(EC.presence_of_element_located((By.XPATH, "//form[@name='search_form']//input[@name='search_input']")))
  35. #search.send_keys('Kevin Rose')
  36. #search.send_keys(Keys.ENTER)
  37.  
  38. # follow the link
  39. link = wait.until(EC.presence_of_element_located((By.LINK_TEXT, "READ MORE")))
  40. link.click()
  41.  
  42. #open new tabs from matching 'view our services' - only opens single match
  43. body = wait.until(EC.presence_of_element_located((By.LINK_TEXT, "View Our Services")))
  44.  
  45. #trying to find by partial link text
  46. #for i in range(0,999999):
  47. # body = driver.find_elements_by_link_text('View Our Services')
  48. # webbrowser.open(body)
  49. # body[i].click()
  50.  
  51. #------
  52. #find all mathes of text
  53. #for i in range(0,6):
  54. # matches = wait.until(EC.presence_of_element_located((By.LINK_TEXT, "View Our Services")))
  55. # matches[i].new_tab()
  56. #------
  57. ActionChains(driver) \
  58. .key_down(Keys.CONTROL) \
  59. .click(body) \
  60. .key_up(Keys.CONTROL) \
  61. .perform()
  62. #body.send_keys(Keys.CONTROL)
  63. #body.click()
  64.  
  65.  
  66. #-- include('examples/showgrabfullscreen.py') --#
  67.  
  68. if __name__ == "__main__":
  69. # fullscreen
  70. im=ImageGrab.grab_to_file('somefile.png')
  71. # im.show()
  72. #-#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement