自定义is_element_present执行速度慢
我在另一个方法的方法体中:
for i in range(60):
try:
if sel.is_element_present("//div[@id='result']/form[3]/strong/div/button"): break
except: pass
time.sleep(1)
它在 5 秒内执行。
现场没有任何变化,我执行了这一行:
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)
它执行了近 30 秒,所以这很奇怪。
你有什么想法吗?
I have in method body of another method:
for i in range(60):
try:
if sel.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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
快速查看您的代码,我唯一能看到的是您在第一个示例中定义了一个标准字符串,但在第二个示例中定义了一个 unicode 字符串。
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.
以下是 is_element_present 方法的内容:
由于它已经执行了 try... except 块,因此您不需要再次将其包装在 try... except 中。由于 is_element_present 只会返回 True 或 False,因此代码的 except: pass 部分可能永远不会被执行。相反,只需使用 if 语句即可。
我还认为您的代码中有一个拼写错误(“sel”而不是“self”)。
Here is what I have for the is_element_present method:
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").