WebDriverWait is not waiting for the element I specify
As an alternative you can induce WebDriverWait for the ElementIsVisible()
and you can use the following Locator Strategy:
string messageText = new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementIsVisible(By.ClassName("block-ui-message"))).GetAttribute("innerHTML");
Using DotNetSeleniumExtras.WaitHelpers
with nuget
:
Not that super clear what exactly you meant by specific using directive I need. In-case you are using SeleniumExtras and WaitHelpers you can use the following solution:
string messageText = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.ClassName("block-ui-message"))).GetAttribute("innerHTML");
Selenium Explicit Waits for invisibility_of_element() not waiting at all
You are passing a By.locator
so instead of invisibility_of_element()
you must be using invisibility_of_element_located()
.
First to wait for the visibility and then for the invisibility of the element you need to:
First induce WebDriverWait for the visibility_of_element_located()
Then induce WebDriverWait for the invisibility_of_element as follows:
WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='loader']")))
WebDriverWait(driver, 30).until(EC.invisibility_of_element_located((By.XPATH, "//div[@class='loader']")))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
Selenium / C# WebDriverWait Not Waiting
You are initiating the Wait, but not waiting for anything. You probably want to do something similar to:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(100));
// wait.Until(By.Id("ButtonSPFlag"));
IWebElement element = wait.Until(driver => driver.FindElement(By.Id("ButtonSPFlag")));
element.Click();
Alternatively you can set implicit wait, but I would go with the first one.
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
Selenium WebDriver WebDriverWait. how to wait for a set of identical elements?
My problem was: the site don't load block while it not in focus in browser.
Desision is - scroll to all div`s your need:
self.driver.get(url_)
product_elements = self.driver.find_elements_by_class_name("product-cards")
for elm in product_elements:
elm.location_once_scrolled_into_view
WebDriverWait not working as expected
Once you wait for the element and moving forward as you are trying to invoke click()
method instead of using presence_of_element_located()
method you need to use element_to_be_clickable()
as follows :
try:
myElem = WebDriverWait(self.browser, delay).until(EC.element_to_be_clickable((By.XPATH , xpath)))
Update
As per your counter question in the comments here are the details of the three methods :
presence_of_element_located
presence_of_element_located(locator) is defined as follows :
class selenium.webdriver.support.expected_conditions.presence_of_element_located(locator)
Parameter : locator - used to find the element returns the WebElement once it is located
Description : An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible or interactable (i.e. clickable).
visibility_of_element_located
visibility_of_element_located(locator) is defined as follows :
class selenium.webdriver.support.expected_conditions.visibility_of_element_located(locator)
Parameter : locator - used to find the element returns the WebElement once it is located and visible
Description : An expectation for checking that an element is present on the DOM of a page and visible. Visibility means that the element is not only displayed but also has a height and width that is greater than 0.
element_to_be_clickable
element_to_be_clickable(locator) is defined as follows :
class selenium.webdriver.support.expected_conditions.element_to_be_clickable(locator)
Parameter : locator - used to find the element returns the WebElement once it is visible, enabled and interactable (i.e. clickable).
Description : An Expectation for checking an element is visible, enabled and interactable such that you can click it.
Python selenium wait until not waiting to search appear
Induce WebDriverWait
() and element_to_be_clickable
() and following xpath
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//select[@id='potentialrecipients']//option[@value='39676']"))).click()
You need to import following libraries.
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
Using Linq to Concatenate Strings
How to Make an Event in the Usercontrol and Have It Handled in the Main Form
Why Can't I Have Abstract Static Methods in C#
Adding Placeholder Text to Textbox
Wait Until File Is Completely Written
A Field Initializer Cannot Reference the Non-Static Field, Method, or Property
Can One Executable Be Both a Console and Gui Application
How to Get the Public Ip Address of a User in C#
What Is the Memory Overhead of a .Net Object
C# SQL Server - Passing a List to a Stored Procedure
How to Both Read and Write a File in C#
How to Create a Custom Membership Provider for ASP.NET MVC 2
When Should I Dispose of a Data Context
How to Set a Program to Launch at Startup
Solution for Overloaded Operator Constraint in .Net Generics
What Is the Use of Observablecollection in .Net
Opensubkey() Returns Null for a Registry Key That I Can See in Regedit.Exe