1

After filling a form I am trying to click the following submit button:

<div class="tl_formbody_submit">
   <div class="tl_submit_container">
     <input type="submit" class="tl_submit" value="Einstellungen speichern" onclick="Backend.getScrollOffset()">
</div>

The code is:

browser.find_by_xpath('//input[@class="tl_submit"]').click()

The stacktrace says, that the element is not visible - but why?

Thanks!

Mohsin Awan
  • 1,176
  • 2
  • 12
  • 29

3 Answers3

1
# import options 
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By

# desired url link 
URL = 'www.path.com'

#driver & settings 
driver = webdriver.Chrome('PATH TO CHROMEDRIVER.EXE')
driver.get('URL')
driver.delete_all_cookies

#find element & click 
driver.find_element_by_id("Einstellungen speichern").click()
KickAds
  • 41
  • 3
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – Giulio Caccin Sep 01 '19 at 06:26
0

if the stacktrace says element is not visible, if means it's not visible when you are trying to find it.

may be some action requires to make it visible (some ajax request) or may be you just need to wait a while before you click it.

you could use explicit wait as mentioned below.

submit_button = WebDriverWait(driver, 30).until(EC.visibility_of_any_elements_located((By.XPATH, "//input[@class='tl_submit']")))
submit_button.click()
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137
0

One of the reason for the element to be 'not visible' is due to the error in assigning the xpath. Best way is to copy the xpath from the html (inspect element) and paste it. It works for most of the cases, try it.

You can check the link below, I had got a similar problem too, the possible solution can be here but for me the above-mentioned solution was fine. How to fix "Element not interactable" Selenium error in Python?

Abanish Tiwari
  • 167
  • 1
  • 2
  • 14