Guest User

Untitled

a guest
Jun 20th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. def login_(browser):
  2. try:
  3. browser.get("some_url")
  4. # user credentials
  5. user = browser.find_element_by_xpath('//*[@id="username"]')
  6. user.send_keys(config('user'))
  7. password = browser.find_element_by_xpath('//*[@id="password"]')
  8. password.send_keys(config('pass'))
  9. login = browser.find_element_by_xpath('/html/body/div[1]/div/button')
  10. login.send_keys("n")
  11. time.sleep(1)
  12. sidebar = browser.find_element_by_xpath('//*[@id="sidebar"]/ul/li[1]/a')
  13. sidebar.send_keys("n")
  14. app_submit = browser.find_element_by_xpath('//*[@id="sidebar"]/ul/li[1]/ul/li[1]/a')
  15. app_submit.send_keys("n")
  16. except TimeoutException or NoSuchElementException:
  17. raise LoginException
  18.  
  19. Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="sidebar"]/ul/li[1]/a"}
  20. (Session info: headless chrome=67.0.3396.79)
  21. (Driver info: chromedriver=2.40.565383 (76257d1ab79276b2d53ee97XXX),platform=Linux 4.4.0-116-generic x86_64)
  22.  
  23. def initiate_webdriver():
  24. option = webdriver.ChromeOptions()
  25. option.binary_location = config('GOOGLE_CHROME_BIN')
  26. option.add_argument('--disable-gpu')
  27. option.add_argument('window-size=1600,900')
  28. option.add_argument('--no-sandbox')
  29. if not config('DEBUG', cast=bool):
  30. display = Display(visible=0, size=(1600, 900))
  31. display.start()
  32. option.add_argument("--headless")
  33. else:
  34. option.add_argument("--incognito")
  35. return webdriver.Chrome(executable_path=config('CHROMEDRIVER_PATH'), chrome_options=option)
Add Comment
Please, Sign In to add comment