'Type object 'By' has no attribute 'Link_text'
Get tired to guess proper syntax. Please, help me out with my problem! Writing code in Python3.
My code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
url = "https://www.instagram.com/"
driver = webdriver.Chrome("/users/vp/desktop/Python/chromedriver")
try:
driver.get(url)
time.sleep(5)
login = driver.find_element(By.Link_text, 'Forgot password?').click()
finally:
driver.close()
driver.quit()
"Forgot password?" html:
a class="_2Lks6" href="/accounts/password/reset/" tabindex="0" xpath="1">Forgot password? a>
Solution 1:[1]
I would change "Link_Text" to "LINK_TEXT" reason being selenium requires it to be in "all caps" or else it won't recognize the By. Method
I assume the original poster has already figured this one out or reverted to the depreciated method. I just wanted to add this answer for anyone else whom may have the same error without realizing the issue instead of being forced to use a depreciated method.
Solution 2:[2]
The issue is not a syntax error, but trying to access an attribute that is not there for an object. you can read about this here: https://docs.python.org/3/library/exceptions.html#TypeError
In your case, By
(object) does not have an attribute called Link_text
.
I guess supported attributes for By
are listed here:
https://www.selenium.dev/selenium/docs/api/py/_modules/selenium/webdriver/common/by.html#By
or
you can do the following to list the attributes
dir(By)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Justin Rutkowski |
Solution 2 | navyad |