selenium python不支持phantomjs,但可以使用Firefox

2024-10-04 01:25:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用下面的代码按最近的选项排序,但它给出了下面的错误

错误

Message: {"errorMessage":"Unable to find element with css selector 'span.sortedLabel'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"107","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:34510","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"css selector\", \"value\": \"span.sortedLabel\", \"sessionId\": \"f5246520-f7d4-11e7-a9f4-adb0a497f49e\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/f5246520-f7d4-11e7-a9f4-adb0a497f49e/element"}}

截图:可通过屏幕获取

Firefox可以正常工作,但phantomjs却不行。在

代码如下:

^{pr2}$

有什么解决办法吗?在


Tags: 代码jsonapplication错误elementcontentselectorcss
1条回答
网友
1楼 · 发布于 2024-10-04 01:25:21

看起来你没有执行任何超时。FF和PahntomJS可能在页面被认为是完全加载的情况下执行不同的操作,这可能导致FF工作正常而PhantomJS无法正常工作的情况。要快速调试此行为,只需在阳离子之间添加一些隐式等待,看看它们是否有帮助。如果有效,则将隐式等待替换为适当的显式等待。在

隐式等待10秒的示例:

driver.implicitly_wait(10) # seconds

相关问题 更多 >