简体   繁体   English

我如何处理Selenium Web驱动程序中的动态“ Id”?

[英]how i can handle dynamic “Id” in Selenium web driver?

How i can handle Dynamic "id" in Selenium Web driver, In my web form there is multiple session(eg session start date and session end date) when i create a new session id of session is change how i can handle dynamic id in selenium webdriver? 我如何处理Selenium Web驱动程序中的动态“ ID”,在我的Web表单中,当我创建会话的新会话ID时会有多个会话(例如,会话开始日期和会话结束日期)改变了我如何处理Selenium中的动态ID网络驱动程序?

Html code HTML代码

<td id="_start_time_td_3" class="ui-widget-content">
    <input type="text" id="_start_time_3"
        name="start_time[]" maxlength="100" style="width: 120px;
        text-align: left;" class="starttime" required="required">
</td>

Selenium code 硒代码

driver.findElement(By.id("_start_time_1")).click();
driver.findElement(By.xpath("//div[10]/div/div[2]/table/tbody/tr/td[4]/div")).click();
driver.findElement(By.id("_end_time_1")).click();
driver.findElement(By.xpath("//div[11]/div/div[2]/table/tbody/tr/td[5]/div")).click();

you can select the element by classname instead of id 您可以通过类名而不是ID选择元素

driver.findElement(By.xpath("//input[@class='starttime']"));

or using contains 或使用包含

 driver.findElement(By.xpath("//input[contains(@id,'start_time')]"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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