How to fix the "Element Currently Not Visible" Selenium <a> Element
I am trying to click an item <a>inside <div>. Here is the html:
<div class="cart__checkout cart__checkout--small">
<a class="button button--lg button--info button--checkout" title = "Checkout" href = "https://shop.adidas.ae/en/checkout/onepage/">
<span> Checkout </span>
<i class="icon-sprite icon-sprite-arrow-white-right-type-4"></i>
</a>
</div>
<button id="update_cart_action" class = "button btn-update" style = "display: none;" type = "submit" name = "update_cart_action" value = "update_qty" title = "Update Shopping Cart"></button>
If you want to see the source site https://shop.adidas.ae/en/checkout/cart/ (you will need to add something to your cart to see what I see)
I tried three different ways:
First of all, I aim at divusing:
var checkoutButton = driver.FindElement(By.ClassName("cart__checkout cart__checkout--small"));
(then click)
To whom I get the error:
"OpenQA.Selenium.InvalidSelectorException" WebDriver.dll : cart__checkout cart__checkout - , WebElement. : InvalidSelectorError:
, :
var checkoutButton = driver.FindElement(By.CssSelector("div[class*= 'cart__checkout cart__checkout--small']"));
, , , ( ).
, , , div , . , div, , , div . Click()?
a :
var checkoutButton = driver.FindElement(By.CssSelector("a[class*='button button--lg button--info button--checkout']"));
, , , a div
:
"OpenQA.Selenium.ElementNotVisibleException" WebDriver.dll :
. , - . Click()? .
Try using WebDriverWaitto wait for an item to become visible, and click a button ExpectedConditions.ElementToBeClickablebefore interacting, as shown below: -
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement checkOut = wait.Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("a.button--checkout[title ='Checkout']")));
checkOut.Click();