开发者

Jquery doesn't find element in selenium

 sel.add_script( sel.get_location(), "jquery.js")

 #here I get  u'fd6c42bcc770ca9decc4f358df3688290a4257ad'`  
       idOfResultWithSomeImage=sel.get_eval("window.jQuery('#result').find('img').filter('[alt=SeleImage]').eq(0).parents('form:first').find('a').eq(1).attr('id')")`

    #here I get u"window.jQue开发者_Python百科ry('#fd6c42bcc770ca9decc4f358df3688290a4257ad').parent().find('button')"
        pathOfButton="window.jQuery('#" + idOfResultWithSomeImage+ "').parent().find('button')"

        #here I get false :/ 
        isButtonPreset = sel.is_element_present(pathOfButton)
        #so here I get error. Element not present.
        sel.click(pathOfButton)

When I check this in firebug's console it find me this button.

I'm using

# -*- coding: utf-8 -*-

and I'm coding in WingIde.

Have you idea why is that?

EDIT

#from here I get 08f0ddbfa71df43bee87d9becdec5ced4ead3419
idOfResultWithRyanairFlight=sel.get_eval("window.jQuery('#result').find('img').filter('[alt=Ryanair]').eq(0).parents('form:first').find('a').eq(1).attr('id')")

I check in debug mode and :

#it returns true
sel.is_element_present("css=#08f0ddbfa71df43bee87d9becdec5ced4ead3419")
#it returns false
sel.is_element_present("window.jQuery('#08f0ddbfa71df43bee87d9becdec5ced4ead3419')")
#it return false
sel.is_element_present("window.jQuery(#08f0ddbfa71df43bee87d9becdec5ced4ead3419)")

I put this queries in firebug console and first and second work.

EDIT

What is interesting, I wrote the same script in c# and I have the same problem.

 var dOfA = selenium.GetEval("window.jQuery('#result').find('img').filter('[alt=SomeIMG]').eq(0).parents('form:first').find('a').eq(1).attr('id')");


            var a=selenium.IsElementPresent("window.jQuery('#" + dOfA + "').parent().find('button')");
            var b = selenium.IsElementPresent("$('#" + dOfA + "')");
            var c = selenium.IsElementPresent("jQuery('#" + dOfA + "')");
            var d = selenium.IsElementPresent("css=#" + dOfA);
            var e = selenium.GetEval("window.jQuery('#" + dOfA + "')");

Only d is true.


If you want to use a CSS/jQuery style selector in Selenium, I think you have to go all the way to using the CSS selector. In other words, you need something like:

pathOfButton = "css=#" + idOfResultWithSomeImage + " ~ button"
if (!sel.is_element_present(pathOfButton))
    pathOfButton = "css=button ~ #" + idOfResultWithSomeImage

sel.click(pathOfButton)

There's probably a slightly better way to do this; also, I've not programmed in python, so my syntax may be off.

See this Selenium documentation page for more locator information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜