6

below is the inspected code, when the mouse is hovererd above the image, and basically i want the image to be clicked....

<ul id="product-list">

    <li class="product one-col new">
        <ul>
            <li class="image" title="sample image">
                <a href="#product/1d77e790-f74a-3859-97db-c513cbece39c">
                    <img width="" height="" alt="" src="/content/images/1.jpg"></img>
                    <span class="new"> … </span>
                    <span class="hover"></span>
                </a>
                <p class="retailer"> … </p>
                <p class="brand"></p>
            </li>
            <li class="price"> … </li>
            <li class="name" title="sample image"> … </li>
            <li class="first-seen"> … </li>
        </ul>
    </li>
    <li class="product one-col new"> … </li>
    <li class="product one-col new"> … </li>
    <li class="product one-col new"> … </li>

i am using python selenium, and have tried the below to click the span (hover) link

browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image > a > span.hover ").click

however this does not work...any idea?

update:

browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image > a > span.hover ").click()


 File "/usr/lib/python2.7/site-packages/selenium-2.35.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 164, in check_response
    raise exception_class(message, screen, stacktrace)
ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace: 
    at fxdriver.preconditions.visible (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:8231)
    at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:10823)
    at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:10840)
    at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:10845)
    at DelayedCommand.prototype.execute/< (file:///tmp/tmp6Pgi9F/extensions/[email protected]/components/command_processor.js:10787) 

update:

this does not work too...

browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image > a ").click()

update:

also tried actionchains , mouse click..still no luck..

element = browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image")
    hov = ActionChains(browser).move_to_element(element)
    hov.click()

SOLVED: finally this worked...

element_to_hover_over = driver.find_element_by_css_selector("ul#product-list > :first-child ")
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()
if "" == driver.find_element_by_css_selector("span.hover").text:
    driver.find_element_by_css_selector("span.hover").click()
2
  • in ur solution, is that hover (variable name) the same one that is called later on "span.hover" ? Commented Oct 15, 2013 at 14:27
  • no..the first hover is a variable..the second one is a class name for span tag Commented Oct 15, 2013 at 14:40

2 Answers 2

3

Your code missing (). Without (), click method is not called.

browser.find_element_by_css_selector("ul...span.hover ").click()
#                                                             ^^

element = browser.find_element_by_css_selector("ul#product-list > :first-child > ul > li.image > a > span.hover ")
browser.execute_script("arguments[0].innerText = 'asdf';", element)
element.click()
Sign up to request clarification or add additional context in comments.

9 Comments

thanks, now i get this... ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace:
@krisdigitx, The element does not contain any text. If I add some text to the element it works.
same here, it shows element does not exist, this is the main html source, pastebin.com/4h6aSvFp
@krisdigitx, new html source does not contain the element. ??
yeah i think its dynamic
|
0

this worked:

element_to_hover_over = driver.find_element_by_css_selector("ul#product-list > :first-child ")
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()
if "" == driver.find_element_by_css_selector("span.hover").text:
    driver.find_element_by_css_selector("span.hover").click()

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.