This is the error that is returned in my console:
AttributeError: 'WebDriver' object has no attribute 'find_element_by_link_text'
When I look at the source code of the site I am using, the link I want is inside of this iframe, although I can clearly see the link and iframe tag are not on separate source pages, so I assume they are actually on the same code. I tried to remove the iframe line but it still didn't work. Am I missing something maybe an import I'm not aware of?
I had to xxx out some of my info here for privacy purposes.
` from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
driver.get("https://webaddress.com")
assert "xxx" in driver.title
elem = driver.find_element(By.NAME, "email")
elem.clear()
elem.send_keys("[email protected]")
elem = driver.find_element(By.NAME, "password")
elem.clear()
elem.send_keys("youvegotma!1")
elem.send_keys(Keys.RETURN)
driver.get("https://webaddress.com/page2")
wait = WebDriverWait(driver, 30)
element = wait.until(EC.title_contains("xxxx"))
assert "xxxx" in driver.title
driver.switch_to.frame("IFramePanelNameHere")
driver.find_element_by_link_text("the link text goes here").Click()
`
CodePudding user response:
Looks like you are using Selenium 4.
Selenium 4 does not support find_element_by_link_text
as well as any other find_element_by_*
methods.
A new syntax should be used, as following:
driver.find_element(By.LINK_TEXT, "the link text goes here").click()
In the same manner it will be
driver.find_element(By.XPATH, "the xpath expression").click()
and
driver.find_element(By.CSS_SELECTOR, "the css selector expression").click()
etc.
Also, the click()
method is lowercased, not Click()