Link to home
Create AccountLog in
Avatar of sharingsunshine
sharingsunshineFlag for United States of America

asked on

Python Selenium Webdriver Login Issues On Mac

I had this question after viewing Using Python To Iterate Through All Website Pages And Paste Changed Content Back.

I am able to open https://www.blogger.com/about/ but then I need to click on the SIGN IN link at the top right of the screen and then insert my username and password but keep getting strange errors.  I am using Python 3.3.6 and Selenium 2.53.6

I am getting this error in my code
File "expertsBrazil2webdriver.py", line 16, in <module>
    driver.findElement (By.linkText("SIGN IN")).click()
AttributeError: 'WebDriver' object has no attribute 'findElement'

Open in new window


Here is the code I am using
from selenium import webdriver
from selenium.webdriver.common.proxy import *
import traceback
import random
import os
import time

os.environ["SELENIUM_SERVER_JAR"] = "/Users/rjw/Documents/Python/selenium-server-standalone-3$

browser = None
try:
  # browser = webdriver.Firefox()
    driver = webdriver.Safari()
    driver.get('https://www.blogger.com/about/')   # navigate to your blog
    time.sleep(5)
    driver.findElement (By.linkText("SIGN IN")).click()
except:
    print(traceback.format_exc())
finally:
    if browser:
        browser.quit()

Open in new window

Avatar of Walter Ritzel
Walter Ritzel
Flag of Brazil image

The correct method is find_element not findElement.
Example from Selenium Documentation:
cheese = driver.find_element(By.LINK_TEXT, "cheese")

Open in new window

Avatar of sharingsunshine

ASKER

I am getting this error  

 File "expertsBrazil2webdriver.py", line 16, in <module>
    SIGN_IN = driver.find_element(By.LINK_TEXT, "SIGN IN")
NameError: name 'By' is not defined

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Walter Ritzel
Walter Ritzel
Flag of Brazil image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
that was right on.  As always, great help you give.
You can actually use  
driver.find_element_by_link_text('SIGN IN').click()

Open in new window

This will work fine.