列表中存储的元素未被单击,";“点错误时不可单击”;在selenium java中

列表中存储的元素未被单击,";“点错误时不可单击”;在selenium java中,java,selenium,Java,Selenium,我正在尝试从保存在列表中的项目列表中查找元素。然而,当我试图通过给出其索引号来单击该元素时,我得到了错误“element not clickable”。这是我的密码: package TestCases; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.Chro

我正在尝试从保存在列表中的项目列表中查找元素。然而,当我试图通过给出其索引号来单击该元素时,我得到了错误“element not clickable”。这是我的密码:

package TestCases;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.List;

import Utility.BarneyTestData;
import Utility.Constants;
import Utility.UtilityMethods;

public class AnonymousUserPurchase {
    // static WebDriver driver;
    UtilityMethods util = new UtilityMethods();

    @BeforeClass
    public void launchBrowser() {

        UtilityMethods.openBrowser(Constants.BROWSER_NAME);
        UtilityMethods.launchWebsite(Constants.URL);

    }

    @Test

    public void PurchaseItemTest() throws InterruptedException, IOException {
        Thread.sleep(9000);

        util.clickElement(Constants.MENCATEGORYTAB);
        util.clickbyXpath(Constants.MENTHIRTS);

        List<WebElement> element = util.getdriver().findElements(By.className(BarneyTestData.getValueOfExcel(0, 1)));
        System.out.println(element);
        Thread.sleep(5000);

        element.get(1).click();
    }

}
封装测试用例;
导入org.openqa.selenium.By;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.WebElement;
导入org.openqa.selenium.chrome.ChromeDriver;
导入org.testng.annotations.BeforeClass;
导入org.testng.annotations.Test;
导入java.io.IOException;
导入java.util.List;
导入Utility.BarneyTestData;
导入实用程序常量;
导入Utility.UtilityMethods;
公共类匿名用户购买{
//静态网络驱动程序;
UtilityMethods util=新的UtilityMethods();
@课前
公共void启动浏览器(){
实用方法.openBrowser(常量.BROWSER\u名称);
启动网站(Constants.URL);
}
@试验
public void PurchaseItemTest()引发InterruptedException,IOException{
睡眠(9000);
util.clickElement(Constants.MENCATEGORYTAB);
util.clickbyXpath(Constants.MENTHIRTS);
List元素=util.getdriver().findElements(By.className(BarneyTestData.getValueOfExcel(0,1));
系统输出打印项次(元素);
睡眠(5000);
元素。获取(1)。单击();
}
}
//页面的Html代码

<a href="/product/alpha-industries-thedrop-40barneys-3a-m-65-defender--22love-trumps-hate-22-field-jacket-505380835.html" class="brand-link" precog_scanned="true">
                    Alpha Industries
                </a>


<a href="/product/alpha-industries-thedrop-40barneys-3a-m-65-defender--22love-trumps-hate-22-field-jacket-505380835.html" class="name-link" precog_scanned="true">thedrop@barneys: M-65 Defender "Love Trumps Hate" Field Jacket</a>

根据错误,您可以使用action类单击元素

语法:

Actions action = new Actions(driver);
action.moveToElement("Your Element").click().perform();

为此,Selenium模拟真实用户,这意味着不显示或隐藏的元素将不可单击。 您可以使用如下Javascript执行器绕过该规则来解决此问题:

((IJavaScriptExecutor)Browser.Driver).ExecuteScript("arguments[0].click();", _element);
其中_元素是要与之交互的Web元素

或者使用等待条件

更多信息请点击此处:

Chris,根据您提到的这是一个列表,并且我看到您已经导入了Selenium Select库,我猜您正在尝试访问一个Select元素,但不正确。发布HTML代码会有所帮助,但恕我直言,我认为你应该考虑使用一个在线的SE课程。我以前尝试使用SELECT类,但是删除了编码。但是忘了删除未使用的导入class.HTML/Url。Chris,您可能做得对,这可能是一个选择,但是如果没有看到页面的HTML源代码,我们就无法判断。@Bill我已经为元素粘贴了HTML代码,请检查。尝试了,没有帮助。