<div class="ant-select-lg homeLocation_select_dummy ant-select ant-select-enabled" style="width: 100%;"><div class="ant-select-selection
ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="0"><div class="ant-select-selection__rendered"><div unselectable="unselectable" class="ant-select-selection__placeholder" style="display: block; user-select: none;">Select</div></div><span class="ant-select-arrow" unselectable="unselectable" style="user-select: none;"><b></b></span></div></div>
<div class="ant-select-lg homeLocation_select_dummy ant-select ant-select-enabled" style="width: 100%;"><div class="ant-select-selection
ant-select-selection--single" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" tabindex="0"><div class="ant-select-selection__rendered"><div unselectable="unselectable" class="ant-select-selection__placeholder" style="display: block; user-select: none;">Select</div></div><span class="ant-select-arrow" unselectable="unselectable" style="user-select: none;"><b></b></span></div></div>
我需要选择DOM中的第二个元素,两个元素都没有ID且具有相同的类。当我在chrome上测试时,我得到两个具有相同xpath的元素
//div[contains(@class, 'ant-select-lg homeLocation_select_dummy ant-select ant-select-enabled')]
我尝试建立索引,但是程序抛出给定的xpath表达式是错误的异常。
我尝试像这样建立索引:-
driver.findElement(By.xpath("//*(@class='ant-select-lg homeLocation_select_dummy ant-select ant-select-enabled')[2]"));
如何在硒中实现?
答案 0 :(得分:0)
尝试一下。
driver.findElement(By.xpath("(//*[@class='ant-select-lg homeLocation_select_dummy ant-select ant-select-enabled'])[2]"));
答案 1 :(得分:0)
尝试一下:
driver.findElement(By.xpath("//div[@class='ant-select-lg homeLocation_select_dummy ant-select ant-select-enabled'][2]"));
OR
driver.findElement(By.xpath("//div[contains(@class,'ant-select-lg')][2]"));
答案 2 :(得分:0)