开发者

Slow execution of customized is_element_present

I have in method body of another method:

for i in range(60):
    try:
        if sel.开发者_JAVA技巧is_element_present("//div[@id='result']/form[3]/strong/div/button"): break
    except: pass
    time.sleep(1)

and it executes in 5 seconds.

Nothing changes on site and I execute this line:

self.WaitForElement(u"//div[@id='result']/form[3]/strong/div/button")     


def WaitForElement(self,name):
    for i in range(60):
        try:
            if sel.is_element_present(name): break
        except: pass
        time.sleep(1)

and it executes in almost 30 seconds, so it's very weird.

Do you have any idea?


Looking quickly over your code, the only thing I can see is you defined a standard string in the first example but a unicode string in the second.


Here is what I have for the is_element_present method:

   def is_element_present(self, how, what):
    try: self.driver.find_element(by=how, value=what)
    except NoSuchElementException, e: return False
    return True

Since it is already doing a try...except block, you don't need to wrap it in try...except again. Since is_element_present will only return True or False, the except: pass part of your code will probably never be executed. Instead, just use the if statement.

I also think you have a typo in your code ("sel" instead of "self").

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜