selenium.common.exceptions.ElementNotVisibleException: Message: element not visible while trying to access an element with Python + Selenium
This error message...
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
...implies that the desired element was not visible within the HTML DOM while the WebDriver instance was trying to find it.
ElementNotVisibleException
ElementNotVisibleException is thrown when an element is present on the DOM Tree, but it is not visible, and so is not able to be interacted with.
Reason
One possitive take away from ElementNotVisibleException is the fact that the WebElement is present within the HTML and this exception is commonly encountered when trying to click()
or read
an attribute of an element that is hidden from view.
Solution
As ElementNotVisibleException ensures that the WebElement is present within the HTML so the solution ahead would be two folds as per the next steps as detailed below:
If you next step is to read any attribute of the desired element, then you need to induce WebDriverWait in-conjunction with expected_conditions clause set to visibility_of_element_located as follows:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
my_value = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "element_xpath"))).get_attribute("innerHTML")If you next step is to invoke
click()
on the desired element, then you need to induce WebDriverWait in-conjunction with expected_conditions clause set to element_to_be_clickable as follows: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, "element_xpath"))).click()
This usecase
The xpath you constructed as //h1[@class="sign-in-input"]
doesn't match any node. We need to create unique xpath to locate the elements representing Email Address
, Password
and Sign In
button inducing WebDriverWait. The below code block will help you to achieve the same:
from selenium import webdriver
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")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=options, executable_path="C:\\Utility\\BrowserDrivers\\chromedriver.exe")
driver.get('https://www.TheGreatCoursesPlus.com/sign-in')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='modal']//input[@name='email']"))).send_keys("abc@abc.com")
driver.find_element_by_xpath("//div[@id='modal']//input[@name='password']").send_keys("password")
driver.find_element_by_xpath("//div[@id='modal']//button[@class='color-site sign-in-button']").click()
element not visible exception in selenium drop down
As others have mentioned your question isn't really detailed enough to know your exact problem, but there are a couple common ones when working with dropdowns in Selenium that I can point out.
First, you need to make sure the select has actually loaded on the page before you try to find it. So you may need to use a WebDriverWait to do that. Example:
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("smsCarrier")));
Then you can try to locate the dropdown and store it in a WebElement:
WebElement carrierDropdown = driver.findElement(By.id("smsCarrier"));
The trick is, to work with dropdowns you need to then wrap that WebElement in a Select object:
Select carrierSelect = new Select(carrierDropdown);
From there you can use methods on that Select object to manipulate it, such as selecting an option from the dropdown. Example:
carrierSelect.selectByVisibleText("Boost Mobile");
or
carrierSelect.selectByValue("@myboostmobile.com");
Hope that helps!
Selenium Webdriver: Element Not Visible Exception
You have two buttons with given xpath on this page, first is not visible, thats why you are getting ElementNotVisibleException
One is under <div class="loginPopup">
Second (the one you need) is under <div class="page">
So change your xpath to look like this, and it will fix your problem:
By.xpath("//div[@class='page']//div[@id='_loginButton']")
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible while clicking a checkbox through SeleniumWebDriver and Java
Try with javascript click:
public void clickElementWithJS(By locator) {
String jsClickCode = "arguments[0].scrollIntoView(true); arguments[0].click();";
try {
WebElement elementToClick = driver.findElement(locator);
((JavascriptExecutor) driver).executeScript(jsClickCode, elementToClick);
} catch(Exception e) {
System.out.println("Element could not be clicked.. " + e.getMessage());
}
}
Selenium Webdriver Java : Element Not Visible Exception
As per the HTML you have shared the link with text as Members Benefits... is visible once you are Logged In. So to identify the WebElement you have to induce WebDriverWait along with ExpectedConditions clause elementToBeClickable as follows :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.partialLinkText("Members Benefits"))).click();
org.openqa.selenium.ElementNotVisibleException: element not interactable while trying to click an element through selenium
To click on the element with text as Add New you can use either of the following solutions:
cssSelector:
driver.findElement(By.cssSelector("div.tab-content>div#left-tabs-example-pane-metastore>div.title>button.custom-btn create-new-button")).click();
xpath:
driver.findElement(By.xpath("//div[@class='tab-content']/div[@id='left-tabs-example-pane-metastore']/div[contains(@class, 'title')]/button[@class='custom-btn.create-new-button' and text()='Add New']")).click();
Selenium: Element not visible exception for Webpage popup/Alert/Notification message
To Load Page > Click 'Add to cart' > Popup appears with buttons > Press 'Proceed to checkout' you need to to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:
cssSelector:
driver.get("http://automationpractice.com/index.php?id_product=4&controller=product");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("p#add_to_cart>button span"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[title='Proceed to checkout']>span"))).click();xpath:
driver.get("http://automationpractice.com/index.php?id_product=4&controller=product");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//span[text()='Add to cart']"))).click();
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@title='Proceed to checkout']/span"))).click();Browser Snapshot:
You can find a detailed discussion in org.openqa.selenium.ElementNotVisibleException: Element is not currently visible while clicking a checkbox through SeleniumWebDriver and Java
Exception org.openqa.selenium.ElementNotVisibleException: ..element not visible
Try to find element using this code :
WebElement male_radio_button = driver.findElement(By.xpath("//input[@id='u_0_c']"));
Hope it will work!!
ElementNotVisibleException: Message: element not interactable error while trying to click a button through Selenium and Python
The element with text as Close is a dynamic element so to locate the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following solutions:
Using
CSS_SELECTOR
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.action-bar button.c-button.c-button--blue"))).click()
Using
XPATH
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, 'action-bar')]//button[@class='c-button c-button--blue' and normalize-space()='Close']"))).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
Related Topics
How to Get the "Id" After Insert into MySQL Database with Python
Cast Base Class to Derived Class Python (Or More Pythonic Way of Extending Classes)
Python and Beautifulsoup Encoding Issues
Creating Spark Data Structure from Multiline Record
How to Declare an Array in Python
List All the Modules That Are Part of a Python Package
How to Check If a File Is a Valid Image File
Store Mouse Click Event Coordinates with Matplotlib
How to Set Window Size in Selenium Chrome Python
Sqlalchemy Create_All() Does Not Create Tables
Download Image with Selenium Python
Link Atlas/Mkl to an Installed Numpy
Python Numpy Arange Unexpected Results
Defining Private Module Functions in Python