2

I am trying to write a script to help me track my Fitbit communities, but first I need to login to the site. Forgive me as I am a coding novice. I am using Selenium in Python. My code is as follows:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


import time
import re

##Loading selenium to handle java on leaderboard page 
##

path_to_chromedriver = 'C:/python351/chromedriver/chromedriver.exe'
browser2 = webdriver.Chrome(executable_path = path_to_chromedriver)

##Login with selenium
##

login_url = 'https://www.fitbit.com/login'
browser2.get(login_url)
browser2.implicitly_wait(5)


email1 = browser2.find_element_by_name('email')
password1 = browser2.find_element_by_name('password')
email1.click()
email1.clear()
WebDriverWait(browser2, 10)

email1.send_keys('notrealemail@mail.com')
WebDriverWait(browser2, 20)
password1.click()
password1.clear()
WebDriverWait(browser2, 20)

password1.send_keys('madeuppass')
WebDriverWait(browser2, 20)



form1 = browser2.find_element_by_class('common-btn common-btn-submit track-Auth-Login-ClickFitbit')
form1.submit()

When I run it I keep getting the following errors and the email/password boxes do not fill in. Here is the traceback:

C:\python351>python -i slogin.py
[WARNING:..\..\..\..\flash\platform\pepper\pep_module.cpp(63)] SANDBOXED
Vector smash protection is enabled.
Traceback (most recent call last):

      File "slogin.py", line 28, in <module>
        email1.click()
      File "C:\python351\lib\site-packages\selenium\webdriver\remote\webelement.py",
     line 74, in click
        self._execute(Command.CLICK_ELEMENT)
      File "C:\python351\lib\site-packages\selenium\webdriver\remote\webelement.py",
     line 457, in _execute
        return self._parent.execute(command, params)
      File "C:\python351\lib\site-packages\selenium\webdriver\remote\webdriver.py",
    line 233, in execute
        self.error_handler.check_response(response)
      File "C:\python351\lib\site-packages\selenium\webdriver\remote\errorhandler.py
    ", line 194, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.ElementNotVisibleException: Message: element not visi
    ble
      (Session info: chrome=50.0.2661.94)
      (Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7
    c4),platform=Windows NT 6.1 SP1 x86_64)

I have been fiddling with this for hours and I can't get it to work. I see the element not visible error and it made me think I needed a delay, but then I tried to implement it (possibly poorly) and still I am getting errors. I also added the click and clear things as well as I saw those suggestions in other posts. I was able to login with RoboBrowser using the form submit, but some of the stuff I need to access later used java so it ended up being a dead end and now I've switched to Selenium and am stuck.

KernelPanic
  • 2,328
  • 7
  • 47
  • 90
J H
  • 33
  • 4
  • may be use JS injection refer my answer here http://stackoverflow.com/questions/37114800/weird-python-selenium-button-click-behaviour – theRoot May 10 '16 at 05:44

2 Answers2

1

You use WebDriverWait in a wrong way. Please refer to following line:

email = WebDriverWait(browser2, 10).until(EC.presence_of_element_located((By.ID,'email')))

This should allow to wait 10 seconds for required element before throwing an exception

You can also use try/except to catch TimeOut exception:

from selenium.common.exceptions import TimeoutException
try:
    email = WebDriverWait(browser2, 10).until(EC.presence_of_element_located((By.ID,'email')))
except TimeoutException:
    print('No Email input field found')
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • Thanks will implement it properly on a go forward basis. Appreciate the comment. – J H May 10 '16 at 14:17
1

Try out this...

find_element_by_name is not able to find that element so you need to use xpath for it.

Loading selenium to handle java on leaderboard page

#

path_to_chromedriver = 'C:/python351/chromedriver/chromedriver.exe' browser2 = webdriver.Chrome(executable_path = path_to_chromedriver)

Login with selenium

#

login_url = 'https://www.fitbit.com/login'

browser2.get(login_url)

browser2.implicitly_wait(5)

email1 = browser2.find_element_by_xpath(".//*[@id='loginForm']/fieldset/dl/dd[1]/input")

email1.send_keys('notrealemail@mail.com')

password1 = browser2.find_element_by_xpath(".//*[@id='loginForm']/fieldset/dl/dd[2]/input")

password1.send_keys('madeuppass')

form1 = browser2.find_element_by_class('common-btn common-btn-submit track-Auth-Login-ClickFitbit')

form1.click()

#

Do reply if you need more help. I ran this code in Eclipse with java syntax it is working fine.. Happy Learning.. Enjoy :-)

Kishan Patel
  • 1,385
  • 3
  • 13
  • 24