使用Selenium点击提交按钮。

huangapple go评论52阅读模式
英文:

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

&lt;input type=&quot;submit&quot; value=&quot;Log In&quot; class=&quot;btn btn-lg btn-primary btn-block&quot;&gt;

I have tried

driver.find_element(&quot;class&quot;, &quot;btn&quot;).click()

driver.find_element(&quot;class&quot;, &quot;btn btn-lg btn-primary btn-block&quot;).click()

driver.find_element(&quot;value&quot;, &quot;Log In&quot;).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, &quot;btn btn-lg btn-primary btn-block&quot;).click()

but get error

NoSuchElementException: Message: no such element: Unable to locate element: {&quot;method&quot;:&quot;css selector&quot;,&quot;selector&quot;:&quot;.btn btn-lg btn-primary btn-block&quot;}

答案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, &quot;btn btn-lg btn-primary btn-block&quot;).click()

By XPATH:

driver.find_element(By.XPATH, &#39;//input[@value=&quot;Log In&quot;]&#39;).click()

By CSS selector:

driver.find_element(By.CSS_SELECTOR, &#39;input.btn.btn-lg.btn-primary.btn-block&#39;).click()

reference: https://selenium-python.readthedocs.io/locating-elements.html

huangapple
  • 本文由 发表于 2023年5月21日 09:39:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76297961.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定