简体   繁体   中英

Selenium - Click list item from unordered list - Java

I am trying to click on an option (array of images) from an unordered list using Selenium Java.

在此处输入图片说明

在此处输入图片说明

I have tried doing a click on the className of "attachment" but that doesn't seem to pick up the list item that I need to click on.

Is there anyway to pick up something like the data-id?

The code that I have tried:

public void click(By by) {
    waitProvider.waitFor().waitUntilElementIsClickable(by);
    WebElement clickableElement = locate(by);
    Actions actions = new Actions(webDriverProvider.driver());
    actions.moveToElement(clickableElement);
    actions.click().perform();
}

and then we do:

public void selectFirstImage() {
    click("attachment");
}

locate:

public WebElement locate(By by) {
    waitProvider.waitFor().waitUntilVisibilityOfElementLocatedBy(by);
    scrollIntoView(by);
    return webDriverProvider.driver().findElement(by);
}

I think click method call is incorrect. Since click expects By not String it should look like this:

click(new ByCssSelector(".attachment-preview"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM