- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
元素-6ren"> 元素-我正在尝试点击 中的元素.这是 html: Checkout 如果您想查看原始站点,它的 https://shop.adidas.ae/en/c-6ren">
我正在尝试点击 <a>
<div>
中的元素.这是 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>
如果您想查看原始站点,它的 https://shop.adidas.ae/en/checkout/cart/ (您必须将一些东西添加到您的购物车才能看到我看到的)
我尝试了三种不同的方式:
第一种方式,我的目标是 div
与:
var checkoutButton = driver.FindElement(By.ClassName("cart__checkout cart__checkout--small"));
(然后点击)
我得到的错误:
An unhandled exception of type 'OpenQA.Selenium.InvalidSelectorException' occurred in WebDriver.dll Additional information: The given selector cart__checkout cart__checkout--small is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: Compound class names not permitted
为了解决复合类名错误,我尝试了代码:
var checkoutButton = driver.FindElement(By.CssSelector("div[class*= 'cart__checkout cart__checkout--small']"));
没有任何反应,我假设它被点击了,但实际的链接没有被点击(第二个选项)。
我认为这可能是点击实际元素的有效方式,除了 div 实际上比链接大得多。我假设 selenium 在 div 的中心单击,但正如您从下面的屏幕截图中看到的那样,div 的中心没有链接。有什么方法可以抵消我的 Click()
功能?
或者,我尝试将目标设为 a
与:
var checkoutButton = driver.FindElement(By.CssSelector("a[class*='button button--lg button--info button--checkout']"));
这只是给出了它不在当前 View 中的错误,很可能是因为 a
在div
下
错误:
An unhandled exception of type 'OpenQA.Selenium.ElementNotVisibleException' occurred in WebDriver.dll Additional information: Element is not currently visible and so may not be interacted with
谢谢你的帮助。我认为我的第二个选择是最好的选择。有什么方法可以抵消 Click()
?谢谢。
最佳答案
您的 CSS 选择器有点偏离。注意“。”两个类(class)之间。此外,您可以专门针对 a。试试这个:
var checkoutButton = driver.FindElement(By.CssSelector("div.cart__checkout.cart__checkout--small a"));
关于c# - 如何修复 "Element is Currently not Visible"Selenium <a> 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40040308/
我是一名优秀的程序员,十分优秀!