Home > Software design >  how to submit button click by text link
how to submit button click by text link

Time:12-01

I am trying submit form using selenium, but submit button isn't working , How can I submit button through driver.find_element_by_xpath('//button\[@type="submit"\]').click() this isn't working for me.

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
       
driver.get('https://splendour.themerex.net/contact/')
driver.find_element_by_link_text("Get In Touch").click()`

Advance thanks

CodePudding user response:

  1. I guess you are using Selenium 4. If so find_element_by_* are no more supported there. You need to use the modern syntax of driver.find_element(By. as folllowing.
  2. You need to introduce WebDriverWait expected_conditions to wait for element to become clickable.

The following code works

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument("start-maximized")

webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)

url = "https://splendour.themerex.net/contact/"
driver.get(url)

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='submit']"))).click()
  • Related