how to click on link text selenium python

Question:

i tried to click on link text but no work. Unable to locate element: {"method":"link text","selector":"Bán chạy"}

please help me.
My code:
driver.find_element_by_link_text(‘Bán chạy’).click()

https://shopee.vn/search?keyword=iphone

strong text

enter image description here

Answers:

driver.find_elements_by_xpath("//*[contains(text(), ‘Bán chạy”)]").click()

Answered By: msurwillo

You can do it by below way

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

wait = WebDriverWait(driver, 20)
element = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'Bán chạy')]")))
element.click()

OR

wait = WebDriverWait(driver, 20)
    element = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[normalize-space(),'Bán chạy']")))
    element.click()
Answered By: Akzy

A link text is only used to identify the hyperlinks on a web page. It can be determined with the help of an anchor tag <a>. In order to create the hyperlinks on a web page, you can use anchor tags followed by the link text.

Here this element is inside a <div> tag so you can’t select this element using linktext locator you can use XPATH or CSS_SELECTOR like following:

from selenium import webdriver
from selenium.webdriver.common.by import By

driver=webdriver.Chrome()
driver.get("https://shopee.vn/search?keyword=iphone")
driver.find_element(By.XPATH,"//div[contains(text(),'Bán chạy')]").click()
Answered By: Shivam Sharma