【问题标题】:How to increment xpath using loop?如何使用循环增加 xpath?
【发布时间】:2021-01-21 07:46:58
【问题描述】:

我正在尝试自动化时间表,其中 5 个 web 元素具有 -

id='ddlIN_HH_1', ddlIN_HH_2, ddlIN_HH_3, ddlIN_HH_4, ddlIN_HH_5

如果我现在使用

Select s= new Select(driver.findElement(By.xpath("//select[contains(@id,'ddlIN_HH_')]")));
 s.selectByValue("09");

如何为其他 webelements 设置相同的值??

【问题讨论】:

    标签: selenium selenium-webdriver xpath automation selenium-chromedriver


    【解决方案1】:

    使用 findElements 代替 findElement。类似的,

    List<WebElement> dds = driver.findElements(By.xpath("//select[contains(@id,'ddlIN_HH_')]"))
    
    for(dd : dds){
        Select s= new Select(dd);
        s.selectByValue("09");
    }
    

    【讨论】:

    • 有什么方法可以限制前 5 个网页元素??
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 2015-04-15
    • 1970-01-01
    • 2021-12-27
    相关资源
    最近更新 更多