简体   繁体   中英

Attribute error in python while trying to sign in

I am using python (with selenium webdriver) to sign into yahoo.

Below is the code:

import unittest
from   selenium import webdriver
from   selenium.common.exceptions import NoSuchElementException

#Set Selenium firefox browser object
browser = webdriver.Firefox()

#Navigate to desired page
browser.get( 'https://www.yahoo.com/' )

try:
    element = browser.find_element_by_title( 'Sign In' )
except NoSuchElementException:
    self.fail( "found: %s" % 'Sign In' )

Below is the error I see:

element = browser.find_element_by_title( 'Sign In' ) 
AttributeError: 'WebDriver' object has no attribute 'find_element_by_title'

Any suggestions how to fix this error?

Use find_element_by_link_text() instead:

element = browser.find_element_by_link_text('Sign In')

Demo:

>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
>>> browser.get('https://www.yahoo.com/')
>>> element = browser.find_element_by_link_text('Sign In')
>>> element
<selenium.webdriver.remote.webelement.WebElement object at 0x1087fc5d0>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM