0

I've seen this error everywhere, but none of the solutions have seemed to work.

This is my code:

contpayment = driver.find_element_by_class_name('nsg-bg--nike-orange')

contpayment.click()

Python/selenium finds this element perfectly, but when trying to click it throws an eception:

"ElementNotVisibleException: Message: element not visible"

I've even tried adding a time.sleep(10) to ensure the page has completely loaded, but it still returns the same exception... Even finding by XPath and id gives the same.

Here is the HTML Code:

<button type="button" id="shippingSubmit" name="shipSubmit" class="visible-
xs-block hidden-sm nsg-button--thin nsg-bg--nike-orange uppercase change-
section-button ng-binding" ng-click="sendForm('Payment')">Continue to Payment </button>

Any help would be appreciated !

Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
asked May 24, 2018 at 7:02
3
  • Please share the html code. Commented May 24, 2018 at 7:03
  • html code has been added Commented May 24, 2018 at 7:06
  • what if you use find_elements_by_class_name instead of find_element_by_class_name? How many items are returned? That might happen that you have both visible and invisible items matching locator. And the invisible one goes prior to visible. Commented May 24, 2018 at 16:22

3 Answers 3

4

1.Use following XPath Locators:

//button[contains(@id,'shippingSubmit') and (@name,'shipSubmit')];
OR
//button[contains(@id,'shippingSubmit') and starts-with(@class,'visible-xs-block')];
OR
//button[contains(.,'Continue to Payment')];

2. Add Explicit Wait before clicking to the particular button.

contpayment = WebDriverWait(driver, 10).until(
 EC.presence_of_element_located((By.XPATH, "//button[contains(.,'Continue to Payment')]")))
contpayment.click()
answered May 24, 2018 at 7:39
3
  • updated code plz check. Commented May 24, 2018 at 8:23
  • if one not works, Try changing all other XPath. Commented May 24, 2018 at 8:26
  • Does it work's for you? Commented May 26, 2018 at 10:40
0

Use WebDriverWait and visibility_of_element_located to locate the element until the element is visible.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.ID, "shippingSubmit"))) 
element.click()

Alternative:

In case, waiting for the element for visibility is not working, try execute_script.

driver.execute_script("$(arguments[0]).click();", element)
answered May 24, 2018 at 7:12
3
  • That seemed to work however, it looks like the button is like permanently invisible because I just got a timeout exception... weird Commented May 24, 2018 at 7:15
  • See the alternative way. Commented May 24, 2018 at 7:46
  • still getting timeout :/ Commented May 24, 2018 at 7:55
0

Use this below XPath this will work.

driver.findElementByXpath("//button[contains(text(),'Continue to Payment')]");

This xpath will locate the button directly.

Bharat Mane
6,78512 gold badges42 silver badges69 bronze badges
answered May 24, 2018 at 8:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.