gpt4 book ai didi

java - 需要一个复杂的 cssSelector 来区分同一页面上的两个保存按钮

转载 作者:行者123 更新时间:2023-12-02 03:36:27 25 4
gpt4 key购买 nike

同一页面上有两个保存按钮,但我需要单击底部的一个。

这是第一个:

 <a href="javascript:addPhoneNumber('edit')">
<img width="60" height="19" border="0" title="Save" alt="Save" src="../images/save.gif">

这是第二个:

 <a href="javascript:onSave()">
<img width="60" height="19" border="0" title="Save" alt="Save" src="../images/save.gif">

我需要点击第二个。我试过了,但没有骰子:

 WebElement foo5 = (new WebDriverWait(driver, 30))
.until(ExpectedConditions.elementToBeClickable(By.cssSelector("a[href*='javascript:onSave()'][alt='Save']")));
foo5.click();

有什么指点吗?我对 cssselectors 很讨厌。

最佳答案

您好,请按照下面的方式操作

public static void main(String[] args) {
WebDriver driver = new SafariDriver();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// as both button have same title so take them inside the list
List<WebElement> mybuttons = driver.findElements(By.cssSelector("a[type='Save']"));
// Now to verify total number of buttons with type attribute as save
System.out.println("Total buttons on the page is : " +mybuttons.size());

// now we can click buttons on the basis of index as they are inside the
// List now Note in java index starts form zero (0)

mybuttons.get(0).click(); // to click on the First button
mybuttons.get(1).click(); // to click on the Second button
}

关于java - 需要一个复杂的 cssSelector 来区分同一页面上的两个保存按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37390303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com