Selenium webdriver.remote()可以单击元素

发布于 2025-02-08 18:10:05 字数 1029 浏览 0 评论 0原文

我正在使用

Selenium Remote Webdriver django项目进行测试。我有几个Docker容器,这就是为什么我需要使用远程驱动程序的原因。

在我的测试中,我的硒配置如下:

# Inside setUp() method from Django's TestCase
self.firefox_options = webdriver.FirefoxOptions()
self.driver = webdriver.Remote(
    command_executor="http://develop-tandem-marianao-selenium:4444",
    options=self.firefox_options,
)
self.driver.implicitly_wait(2)

问题

是,硒和django项目容器已正确连接,我可以执行测试,但是每当我尝试comply> click> click> click> click> click> comece()方法方法方法,但是我会发现错误

Element <...> could not be scrolled into view

,通过搜索,我发现这样做

self.driver.execute_script("arguments[0].click();", element)

确实有效。我在某个地方读到,当Selenium尝试consc> click()时,网站的某些部分尚未加载可能是一个问题,但这仍然没有告诉我该怎么做。

有什么想法吗?

编辑:我还尝试强迫测试等待(使用time.sleep()),但仍然不起作用。

Situation

I'm using the Selenium Remote webdriver to do my tests on a Django project. I have several Docker containers, which is why I needed to use the Remote driver.

In my test, my Selenium configuration is as follows

# Inside setUp() method from Django's TestCase
self.firefox_options = webdriver.FirefoxOptions()
self.driver = webdriver.Remote(
    command_executor="http://develop-tandem-marianao-selenium:4444",
    options=self.firefox_options,
)
self.driver.implicitly_wait(2)

Problem

Thing is, the Selenium and Django project containers are connected properly and I am able to perform tests, but whenever I try the click() method on any element, I get the error

Element <...> could not be scrolled into view

However, by searching around I found out that doing

self.driver.execute_script("arguments[0].click();", element)

instead does work. I've read somewhere that it might be a problem that some part of the website is not loaded yet when Selenium attempts to click(), but that still doesn't tell me what to do.

Any ideas?

Edit: I've also tried forcing the test to wait (with time.sleep()) and it still doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文