[英]How to click/find button with selenium
I've tried to click the button "Continuar >>" multiples ways by now, but it simply wont work.我已经尝试以多种方式单击“继续>>”按钮,但它根本不起作用。 I've no idea what I'm doing wrong.我不知道我做错了什么。 Any help?有什么帮助吗?
driver = webdriver.Firefox()
driver.get('https://gru.inpi.gov.br/pePI/jsp/marcas/Pesquisa_classe_basica.jsp')
driver.find_element_by_xpath("//input[@type ='submit' and @title='Clique aqui para entrar na pesquisa']").click()
Edit adding the html of the element编辑添加元素的 html
<input type="submit" class="basic" value=" Continuar » " title="Clique aqui para entrar na Pesquisa">
To click on the element with text as Continuar »
you to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies :要单击带有Continuar »
文本的元素Continuar »
您为element_to_be_clickable()
引入WebDriverWait ,您可以使用以下任一定位器策略:
Using CSS_SELECTOR
:使用CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.basic[value=' Continuar » ']"))).click()
Using XPATH
:使用XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='basic' and @value=' Continuar » ']"))).click()
Note : You have to add the following imports :注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
As a quick solution, you can copy the xpath of the element by going to developer tools then right clicking on the element and then Copy> Copy XPath.作为一个快速的解决方案,您可以通过转到开发人员工具然后右键单击元素然后复制> 复制 XPath 来复制元素的 xpath。 This may break depending on your situation though.不过,这可能会中断,具体取决于您的情况。
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://gru.inpi.gov.br/pePI/jsp/marcas/Pesquisa_classe_basica.jsp')
driver.find_element_by_xpath('//*[@id="principal"]/form/table/tbody/tr[3]/td/input').click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.