4

I am using python selenium on browser to fill in some form. I was trying to select an element in the drop-down list,

<a href="#" class="dropdown-toggle select" data-toggle="dropdown">0</a>

but if I try to find it by text using this script:

browser.find_element_by_link_text("0").click()

it result an error: "unknown error: Element is not clickable at point (498, 612). Other element would receive the click: ..."

and if try to find it by class name:

browser.find_element_by_class_name("dropdown-toggle").click()

it result in another error: "element not visible"

is there any way I can click onto that drop-down list? Thanks very much.

7
  • Is that link visible on the page when you load it for the first time? You probably need to click on an other element first before it becomes visible Commented Aug 17, 2015 at 8:47
  • Can you provide some more HTML of the dropdown? Becuase <a href..> is normaly just a link and no dropdown? Have you some <ul><ui> tags around? Maybe you have to open the dropdown first before selecting a value Commented Aug 17, 2015 at 8:53
  • It is visible on the page but there's an element blocking above the button, the html is quite simply as follow: <div class="tckt"><label>How many tickets would you like?</label> <a href="#" class="dropdown-toggle select" data-toggle="dropdown">0</a></div>, it is the <div class="tckt"> blocking over the dropdown and make it not clickable Commented Aug 17, 2015 at 9:09
  • thanks for all the reply, tried all the methods but still no luck... I've paste the html code here: pastebin.com/n6VLQDgA kindly help to see how to click the dropdown: <a href="#" class="dropdown-toggle select" data-toggle="dropdown">0</a> Commented Aug 17, 2015 at 15:42
  • I guess i know where the problem is, that part of code was created via javascript after I clicked some button in the website, maybe that's the reason it is "not visible" in Selenium sense? Is there anyway I can overcome this? Commented Aug 17, 2015 at 17:08

5 Answers 5

2

I had a similar problem. You can execute a script to change the visibility of that element once you find it and then click it.

driver.execute_script("arguments[0].style.visibility = 'visible';",myElement) myElement.click()

Sign up to request clarification or add additional context in comments.

Comments

1

Try to find it by Xpath searching for partial class and text at the same time:

browser.find_element_by_xpath(//a[contains(@class, 'dropdown-toggle select') and contains(text(), '0')]).click();

1 Comment

the problem is not finding the element, the problem is that selenium tries to click the position of the element which is not useful when the element is beyond the current visible part of the webpage.
0

you should get the element by xpath and then press it.

browser.find_element_by_xpath(xpath).

read here how to get the xpath: http://www.wikihow.com/Find-XPath-Using-Firebug

2 Comments

I did, but it still result in the same error "element not visible". Also I have tried ActionChain and still couldn't click it
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
0

Thanks for the feedback, I've found the problem which was due to the new script being loaded by javascript as triggered by some clicks. I've created the following code to capture the exception and retrying until the element is ready:

while True:
    try:
        time.sleep(1)
        browser.find_element_by_xpath("//div[@class='tckt']/a").click()
        print("found")
        break
    except ElementNotVisibleException:
        print("notvisible")
    except WebDriverException:
        print("clickduplicate")

I read it on articles says this happened a lot on radio button for Chrome webdriver, hope this helps.

Comments

-1

Firstly click the parent element by finding it, using it's xpath->find the element you want to click within the parent element like the way you did. i.e

browser.find_element_by_link_text("0").click()

Hope this 2 steps will work for you. Otherwise please post the url with the code you've tried-It'll be easy to find out the issue.

Comments

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.