添加到购物车按钮不起作用,Selenium C# 元素不可交互

Add to cart button not working, Selenium C# element not interactable

我正在自动化以下网站,添加到购物车按钮不起作用: http://automationpractice.com

请使用以下ID密码登录: ID : 保罗@xmail.com 密码:Pass123##

    By addCartTshirt = By.XPath("//*[contains(text(),'Add to cart')]");

    public void Add_To_Cart_T_Shirt()
    {
        driver.FindElement(addCartTshirt).Click();
    }

您可以使用 action 方法来完成,我在 Java 中检查了下面的内容,它对我有用。

Actions action = new Actions(driver);

element = driver.FindElement(By.Xpath("//img[@title='Faded Short Sleeve T-shirts']"))

action.moveToElement(element).perform();

ele = driver.FindElement(By.Xpath("//a[@title='Add to cart']"));

action.moveToElement(ele).click().perform();

别忘了导入

import org.openqa.selenium.interactions.Actions