1

I am trying to click on the link shown below:

<a class="user" href="/Kevin-Rose" action_mousedown="UserLinkClickthrough" id="__w2_L73qRYl_link" 
target="_blank">
         <span class="matched_term">Kevin Rose</span>
</a>

I tried using following code:

 user = driver.find_element_by_xpath("//a[@class='user'][1]")
 user.click()

I got following error:

ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace:

How can I solve this problem?

enter image description here

3
  • Are you sure the link is visible? Can you provide us with a link to the website under test? Commented Sep 12, 2014 at 15:24
  • quora.com/search?q=Kevin+rose Commented Sep 12, 2014 at 15:27
  • Do you want to click any particular link ? Can you post screenshot by highlighting required link to click? Commented Sep 12, 2014 at 15:39

2 Answers 2

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()
Sign up to request clarification or add additional context in comments.

2 Comments

It worked perfectly.Thanks a lot. I was using python shell and executing the code line by line,then why wait is required?
@Siddhesh since quora loads the page asynchronously, not all the elements are there after the initial data comes. Waits is a pretty neat technique comparing to lots of time.sleep() calls.
0

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']"

3 Comments

It didn't give any error but i am on the same page. There are multiple instances of "Kevin Rose" may be that is the reason. My pointer was in the search box when i selected the element. I will try with different indexes and check if it works, but thats again a tedious task.
Do you want to click any particular link ? Can you post screenshot by highlighting required link to click?
I've edited my answer and added xpath. Try with that and let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.