英文:
Using Selenium to click a input type submit button
问题
尝试点击这个
<input type="submit" value="Log In" class="btn btn-lg btn-primary btn-block">
我已经尝试过
driver.find_element("class", "btn").click()
driver.find_element("class", "btn btn-lg btn-primary btn-block").click()
driver.find_element("value", "Log In").click()
但都出现错误
InvalidArgumentException: Message: invalid argument: invalid locator
如何点击它?
编辑:
现在我尝试过
driver.find_element(By.CLASS_NAME, "btn btn-lg btn-primary btn-block").click()
但出现错误
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".btn btn-lg btn-primary btn-block"}
英文:
Trying to click this
<input type="submit" value="Log In" class="btn btn-lg btn-primary btn-block">
I have tried
driver.find_element("class", "btn").click()
driver.find_element("class", "btn btn-lg btn-primary btn-block").click()
driver.find_element("value", "Log In").click()
But all give error
InvalidArgumentException: Message: invalid argument: invalid locator
How can I click on this?
EDIT:
now ive tried
driver.find_element(By.CLASS_NAME, "btn btn-lg btn-primary btn-block").click()
but get error
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".btn btn-lg btn-primary btn-block"}
答案1
得分: 0
尝试使用 "By":
from selenium.webdriver.common.by import By
您可以以不同的方式选择元素:
按类名:
driver.find_element(By.CLASS_NAME, "btn btn-lg btn-primary btn-block").click()
按XPATH:
driver.find_element(By.XPATH, '//input[@value="Log In"]').click()
按CSS选择器:
driver.find_element(By.CSS_SELECTOR, 'input.btn.btn-lg.btn-primary.btn-block').click()
参考链接:https://selenium-python.readthedocs.io/locating-elements.html
英文:
Try using "By"
from selenium.webdriver.common.by import By
And you can select your element it in different ways:
By Class:
driver.find_element(By.CLASS_NAME, "btn btn-lg btn-primary btn-block").click()
By XPATH:
driver.find_element(By.XPATH, '//input[@value="Log In"]').click()
By CSS selector:
driver.find_element(By.CSS_SELECTOR, 'input.btn.btn-lg.btn-primary.btn-block').click()
reference: https://selenium-python.readthedocs.io/locating-elements.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论