我想在使用 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/