python-3.x - Selenium webdriver 在无头 Firefox 中缺少点击
问题描述
我有一个在 Ubuntu Linux(16.04.4 LTS)上使用 Firefox(v59.0.2 64 位)用 python(3.5.2)编写的硒测试。geckodriver 版本为 v0.20.1。我在 Twitter 上自动发布一条推文,在 GUI 模式下它每次都能完美运行。然而,在无头模式下,它每次都会错过对特定元素的相同点击。有没有人见过这个?还有关于在无头模式下调试的任何建议吗?
from selenium.webdriver.support import expected_conditions as ec
# Here is the way I am getting the element
@property
def sending_message_close_button(self):
self._sending_tweets_message_close = self._driver.wait.until(ec.element_to_be_clickable((By.CSS_SELECTOR,
"div.alert-messages.js-message-drawer-visible a.Icon.Icon--close.Icon--medium.dismiss")))
return self._sending_tweets_message_close
这是在同一个类中的方法中单击元素的调用:
self.sending_message_close_button.click()
我尝试使用 ActionBuilder 移动到元素并单击它。我也尝试过点击 javascript。都没有奏效。
以下是我初始化浏览器的方式(为保护隐私,url 已编辑):
@property
def webdriver(self):
if self._webdriver is None:
options = Options()
options.add_argument('-headless')
profile = FirefoxProfile()
profile.set_preference("network.proxy.type", 2)
if self._env == 'demo':
profile.set_preference("network.proxy.autoconfig_url", "")
elif self._env == 'stage':
profile.set_preference("network.proxy.autoconfig_url", "")
profile.set_preference("network.proxy.no_proxies_on", "localhost")
if self._use_options:
self._webdriver = webdriver.Firefox(firefox_profile=profile, options=options)
else:
self._webdriver = webdriver.Firefox(firefox_profile=profile)
self._webdriver.implicitly_wait(10)
return self._webdriver
解决方案
推荐阅读
- c# - 当数据库中的记录发生更改时,如何更新/刷新 Azure Cache for Redis?
- python - 没有名为“googleapiclient”的模块
- laravel - Laravel 资源返回 null
- arrays - np.diff() 在图像中的数组上使用时给出不正确的输出
- firebase - 如何使用 Flutter 通过 Firebase Admin SDK 管理 Firebase 用户
- elasticsearch - 为什么这个索引状态是红色的:opendistro-ism-config
- android - Auth0 - 为什么他们希望用户使用 WebView 而不是从 EditText 获取字符串进行身份验证?
- azure - 如何在 Azure 上部署 keycloak docker 容器?
- google-cloud-firestore - 无法从 Firestore 中删除文档
- javascript - 如何使用 cypress.io 使用两个 Gmail 帐户收件箱