我如何处理动态" Id"在Selenium网络驱动程序中?

时间:2015-12-03 12:23:22

标签: eclipse selenium

我如何处理动态" id"在Selenium Web驱动程序中,在我的Web表单中有多个会话(例如会话开始日期和会话结束日期),当我创建会话的新会话ID更改我如何处理selenium webdriver中的动态ID?

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代码

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();

1 个答案:

答案 0 :(得分:1)

您可以按类名而不是id

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

或使用contains

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