1

I am new to python. I am following some examples found online to learn it.

One of the examples is to use "selenium"

The example use "find_element_by_link_text", But it seems to be missing. I have to use "find_element" option.

I am using following code, but it is giving me error. The Chrome browser does get open error is in find_element part. Can anyone provide some advice on how to fix it?

from selenium import webdriver

browser = webdriver.Chrome()

browser.get("https://github.com")
signin_link = browser.find_element("LINK_TEXT", "Sign in")

print(signin_link)
Janaka
  • 2,505
  • 4
  • 33
  • 57
  • 2
    Your locator approach is incorrect. Either use `BY.` or text-only approach. See valid locators here: https://www.selenium.dev/selenium/docs/api/py/webdriver/selenium.webdriver.common.by.html#selenium.webdriver.common.by.By.CSS_SELECTOR // Also, link the tutorial which you are following. The tutorial may be bad – user47 Aug 09 '22 at 16:58

1 Answers1

0

Functions like find_element_by_x are not supported anymore since v4.0. Use the By class instead.

from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager

browser = webdriver.Chrome(ChromeDriverManager().install())

browser.get("https://github.com")
signin_link = browser.find_element(By.LINK_TEXT, "Sign in")
puncher
  • 1,570
  • 4
  • 15
  • 38