python - 使用 Python (Selenium) 选择提交按钮

标签 python selenium xpath css-selectors webdriverwait

我想在使用 cmd 时使用 Python (Selenium) 自动化 Github 存储库。 我已经到了最后一步:在 Github 上“创建新存储库”,但无法让 python 单击“创建存储库”。

感谢您的每一次帮助。

我尝试过: searchBar = driver.find_elements_by_css_selector('button.first-in-line').click()searchBar = driver.find_elements_by_css_selector('button.first-in-line').submit()


<button type="submit" class="btn btn-primary first-in-line" data-disable-with="Creating repository…">
        Create repository
</button>

我希望 python 自动单击“创建存储库”提交按钮,以完成新的 git 存储库。

最佳答案

当您使用find_elements_by_css_selector时,它将返回一个列表。您必须使用find_element_by_css_selector,而不是find_elements_by_css_selector

driver.find_element_by_css_selector('button.first-in-line').click()

但是,如果您想使用 find_elements_by_css_selector 那么您应该使用索引来获取第一个匹配项,然后单击如下代码。

driver.find_elements_by_css_selector('button.first-in-line')[0].click()

关于python - 使用 Python (Selenium) 选择提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56604119/

相关文章:

php - 如何在PHP中获取 "words"之前或 "words"之后的字符串

javascript - 如何获取网页中元素的x,y坐标?

javascript - 在 Selenium Python 中禁用图像

xml - 如何使用 xmllint 和 XPath 从属性中获取值?

python - UUID 检查使用 python UUID 模块更改 UUID

python搜索/用类似sed的表达式替换正则表达式

python - python读取的复杂Matlab struct mat文件

支持非致命故障的 Python 测试框架

java - 带有页面对象模型页面工厂的 Selenium 网格

xml - 在经典 ASP 中对 XML 数据进行排序