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 !
-
Please share the html code.Prasanna venkatesh– Prasanna venkatesh2018年05月24日 07:03:47 +00:00Commented May 24, 2018 at 7:03
-
html code has been added123ang– 123ang2018年05月24日 07:06:49 +00:00Commented 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.Alexey R.– Alexey R.2018年05月24日 16:22:09 +00:00Commented May 24, 2018 at 16:22
3 Answers 3
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()
-
updated code plz check.2018年05月24日 08:23:28 +00:00Commented May 24, 2018 at 8:23
-
if one not works, Try changing all other XPath.2018年05月24日 08:26:15 +00:00Commented May 24, 2018 at 8:26
-
Does it work's for you?2018年05月26日 10:40:31 +00:00Commented May 26, 2018 at 10:40
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)
-
That seemed to work however, it looks like the button is like permanently invisible because I just got a timeout exception... weird123ang– 123ang2018年05月24日 07:15:47 +00:00Commented May 24, 2018 at 7:15
-
-
Use this below XPath this will work.
driver.findElementByXpath("//button[contains(text(),'Continue to Payment')]");
This xpath will locate the button directly.
Explore related questions
See similar questions with these tags.