0
HTML:如何在硒中点击ul里面的li标签?
<div class="hdetSelect right moreRooms" style="">
<select class="bookedRoom_1 perSelector xsmall number-room-booked_fbc1336de4c882dd" ref="1" id="selectRoomBooked_1" style="display: none;">
<option value="0">0</option>
<option value="1">1</option>
</select>
<div class="nsSelect-container search-num-selector left">
<input class="nsSelect-input bookedRoom_1 perSelector xsmall number-room-booked_fbc1336de4c882dd" type="text" style="display: inline-block;">
<div class="nsSelect-opt-container search-num-selector left rounded5 hide" style="top: 696.8px; left: 875px; display: none;">
<ul>
<li class="clear" style="display: block; width: 27px;">
<a href="#" ref="0" class="">0</a>
</li>
<li style="display: block; width: 27px;">
<a href="#" ref="1" class="active">1</a>
</li></ul>
<a class="nsSelect-close">Cancel</a></div></div>
<span class="dRoom">Room</span>
</div>
我试图点击使用XPath或cssSelector
的UL内的利,但我总是得到错误“没有这样的元素:无法找到”。
这里就是我与努力:
使用JavaScript执行与cssSelector
:
WebElement room_num = driver.findElement(By.cssSelector("div.room-list-item:nth-child(1)> div:nth-child(1)> div:nth-child(4)> div:nth-child(2)> div:nth-child(2)> ul:nth-child(1)> li:nth-child(2)>a"));
executor.executeScript("arguments[0].click();",room_num);
在XPath:
driver.findElement(By.xpath("//*[@id='room-list']/div[1]/div[1]/div[2]/div/div/ul/li[2]/a")).click();
我要选择/点击(UI)里有innerHTML 1,但似乎没有任何工作。我正在用尽想法,所以请留下意见或解决方案。
首先,我会建议你使用Chrome浏览器开发工具,你可以右键单击一个元素并copy-> xpath以使用路径的值 –
是的,我的xpath选择器是从chrome开发工具复制的。 –
比我能想到的唯一原因是dom是在您尝试访问元素后生成的,因为我需要更多关于涉及哪些技术的详细信息e.t.c –