JQuery does not 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.jQuery('#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 the firebug console, it will find me this button.

I use

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

and I code in WingIde.

Do you have an idea why?

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 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 these requests in the firebug console and did the first and second work.

EDIT

Interestingly, 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.

+3
source share
1 answer

If you want to use the CSS / jQuery style selector in Selenium, I think you need 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)

, ; , python, .

. Selenium .

0

Source: https://habr.com/ru/post/1778344/


All Articles