python - 提交在 Django StaticLiveServerTestCase 中使用 Intercooler 的表单

标签 python django selenium

我正在尝试编写一个用于提交表单的 Selenium 测试,它使用 intercooler.js当它被提交时。我遇到的主要问题是,当我导航到该页面时,表单具有 class="disabled",这不是预期的行为,并且我无法提交表单。 intercooler 文档中的相关部分说:

By default, intercooler will apply the disabled class to the element that triggers an intercooler request. This can be used to give a visual hint to the user that they should not click or otherwise trigger the request again, and is Bootstrap-friendly.

但是,在我看来,禁用的类是在我实际提交表单之前添加到表单元素中的,据我所知,它应该只在请求正在进行后添加。

当前的表单如下所示:

<form ic-post-to="/dashboard/calculate/2/exports/" ic-select-from-response="#content" ic-target="#content" method="post" ic-src="/dashboard/calculate/2/exports/" ic-verb="POST" ic-trigger-on="default" ic-deps="ignore" class="disabled">
    <input type="hidden" name="csrfmiddlewaretoken" value="...">
    <input type="submit" name="new" value="New" class="btn btn-primary float-right ml-1" id="submit-id-new">
</form>

我尝试添加显式隐式等待,以便加载整个页面,但问题仍然存在。

任何有关此问题的帮助将不胜感激。

最佳答案

尝试使用Javascript点击按钮:

submit = driver.find_element_by_id("submit-id-new")
driver.execute_script("arguments[0].click();", submit)

关于python - 提交在 Django StaticLiveServerTestCase 中使用 Intercooler 的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51419221/

相关文章:

python - 属性错误 : 'NoneType' object has no attribute '_meta'

python - 使用基于日期/时间的对象进行 Django 单元测试

python - scrollIntoView() 正在向下滚动

python - pipenv 和 bash 别名

python - 安装 win32gui python 模块

python - Django 和 Active Python 2.x 是否适用于带有 IIS 7.5 的 Windows 2008 R2 上的生产环境?

python - Selenium 在生产中仅在 headless 模式下工作是真的吗? ( Django )

python - 使用没有 ID 的 Selenium 查找并单击按钮

python - pyspark:系统找不到指定的路径

python - 如何获得Python long double literal?