Element I am trying to click an item inside
. Here is the html:

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()? .

+4
4

XPATH:

//*[@id = 'cart-form']//a[@title = 'Checkout']

, # :

var checkoutButton = driver.FindElement(By.XPath("//*[@id = 'cart-form']//a[@title = 'Checkout']"))

XPATH , .

0

CSS- . ".". . , . :

var checkoutButton = driver.FindElement(By.CssSelector("div.cart__checkout.cart__checkout--small a"));
+1

, :

ILocatable hoverItem = (ILocatable)driver.FindElement(By.XPath("//*[@id='js-minicart']"));
IMouse mouse = ((IHasInputDevices)driver).Mouse;
mouse.MouseMove(hoverItem.Coordinates);

<a>:

driver.FindElement(By.Xpath('//*[@id="js-minicart"]/li/div[2]/div[3]/div[4]/ul/li/a/span'));
+1

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();
+1
source

Source: https://habr.com/ru/post/1657736/


All Articles