0

I have a problem with click in Selenium, it doesn't click on the button. This is my code:

from selenium import webdriver
import time
import click
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys


driver = webdriver.Chrome()

driver.get("https://help.instagram.com/contact/723586364339719/")

submit_button = driver.find_element_by_xpath('//*[@id="u_0_8"]')
submit_button.click()

This is the HTML code:

<button value="1" class="_42ft _4jy0 _4jy4 _4jy1 selected _51sy" type="submit" id="u_0_8">Enviar</button>
Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
quique99
  • 13
  • 5

3 Answers3

1

You can do it with using explicit wait for the button:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC


WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='u_0_8']"))).click()

I hope it helps you!

Ratmir Asanov
  • 6,237
  • 5
  • 26
  • 40
0

Instead of this:

submit_button = driver.find_element_by_xpath('//*[@id="u_0_8"]')
submit_button.click()

Try this:

driver.find_element_by_id("id='u_0_8']").click()
ParthS007
  • 2,581
  • 1
  • 22
  • 37
  • It doesnt work line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="id='u_0_8']"]"} (Session info: chrome=80.0.3987.132) – quique99 Mar 08 '20 at 14:07
  • Try print(driver.page_source), and check the html actually contains the element. – ParthS007 Mar 08 '20 at 14:08
  • i think it actually contains it, no? view-source:https://help.instagram.com/contact/723586364339719/ – quique99 Mar 08 '20 at 14:13
  • You have to print it and check if it contains the same id or not. – ParthS007 Mar 08 '20 at 14:29
0

The desired element is a dynamic element, so to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://help.instagram.com/contact/723586364339719/')
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[type='submit']"))).click()
    
  • Using XPATH:

    driver.get('https://help.instagram.com/contact/723586364339719/')
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@value='1' and normalize-space()='Send']"))).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
    
  • Browser Snapshot:

instagram_send_click

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352