简体   繁体   中英

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

<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 :

  • Using CSS_SELECTOR :

     WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.basic[value=' Continuar » ']"))).click()
  • Using 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. 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM