Skip to content Skip to sidebar Skip to footer

Unable To Click Link Using Selenium Webdriver In Python

I am trying to click on the link shown below: <

Solution 1:

The problem is that you are finding the element while it is not yet there. Wait for it.

Here's the complete code, from logging in, search to following the first Kevin Rose link:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


URL = "http://www.quora.com"
EMAIL = 'your email here'
PASSWORD = 'your password here'

driver = webdriver.Chrome()  # can be webdriver.Firefox() in your case
driver.get(URL)
wait = WebDriverWait(driver, 10)

# login
form = driver.find_element_by_class_name('regular_login')
username = form.find_element_by_name('email')
username.send_keys(EMAIL)

password = form.find_element_by_name('password')
password.send_keys(PASSWORD)

login_button = form.find_element_by_xpath('//input[@type="submit" and @value="Login"]')
login_button.click()

# search
search = wait.until(EC.presence_of_element_located((By.XPATH, "//form[@name='search_form']//input[@name='search_input']")))
search.send_keys('Kevin Rose')
search.send_keys(Keys.ENTER)

# follow the link
link = wait.until(EC.presence_of_element_located((By.LINK_TEXT, "Kevin Rose")))
link.click()

Solution 2:

Try with below locators

Xpath : "//span[text()='Kevin Rose']"

cssSelector : "a[href*='Kevin-Rose'] > span"

Edit-I

Here is the Xpath to click on Profile name Kevin Rose

"//div[contains(.,'Profile:') and contains(@class,'photo')]/span/a//span[text()='Kevin Rose']"

Post a Comment for "Unable To Click Link Using Selenium Webdriver In Python"