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

3 Answers 3

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!

Sign up to request clarification or add additional context in comments.

Comments

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()

4 Comments

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)
Try print(driver.page_source), and check the html actually contains the element.
i think it actually contains it, no? view-source:help.instagram.com/contact/723586364339719
You have to print it and check if it contains the same id or not.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.