Solved

Python Selenium Webdriver Login Issues On Mac

Posted on 2016-08-19
5
111 Views
Last Modified: 2016-11-15
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

0
Comment
Question by:sharingsunshine
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

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

Open in new window

0
 

Author Comment

by:sharingsunshine
ID: 41763622
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

0
 
LVL 16

Accepted Solution

by:
Walter Ritzel earned 500 total points
ID: 41763824
Add this line on your import section:
from selenium.webdriver.common.by import By

Open in new window

0
 

Author Comment

by:sharingsunshine
ID: 41763877
that was right on.  As always, great help you give.
0
 

Expert Comment

by:Ranadheer Kurakula
ID: 41887721
You can actually use  
driver.find_element_by_link_text('SIGN IN').click()

Open in new window

This will work fine.
1

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Edit linux file using python 4 54
linux crontab output 3 73
Charging Macbook Pro 8 67
Mac OSX Mail client and Exchange 5 40
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question