gpt4 book ai didi

java - 无法从类似于下拉框的弹出窗口中选择值

转载 作者:行者123 更新时间:2023-11-28 12:00:06 25 4
gpt4 key购买 nike

我必须选择类似于下拉框但不是实际下拉框的字段。选择字段在弹出窗口中显示值,其中包含值和子值,我需要选择值。

面临的问题:

无法识别对象,无法从字段中选择值。

我已尝试让 cssSelector 识别对象:“div[class='mailval'][title='Breast > Both']”。它不起作用。

HTML代码如下:

<div class="rowDiv ">
<label for="bodypart">Body Part</label>
<div id="bodypart_box_1">
<div style="position:absolute;left:185px;z-index: 20">
<ul class="parent">
<li>
<div id="main" class="mailval">events=Object { click=[1]}handle=function()
<input id="bodypart_1" class="bodypart" type="text" onfocus="if($(this).hasClass('disabled')){$(this).blur();}" readonly="readonly" value="Select One" name="bodypart_1" title="">
<input id="actualBodypart_1" type="hidden" value="Breast" name="actualBodypart_1">
</div>
<ul id="bodyPartList_1" class="top sub bodyPartList" style="display: none;">olddisplay="block"
<li>
<div class="mailval fly" title="Breast" originaltitle="Breast">Breast</div>events=Object { click=[1], mouseover=[1]}handle=function()
<ul>
<li>
<div class="mailval" title="Breast > Both" originaltitle="Breast > NULL > Both">Both</div>events=Object { click=[1], mouseover=[1]}handle=function()
</li>
<li>
<div class="mailval" title="Breast > Left" originaltitle="Breast > NULL > Left">Left</div>events=Object { click=[1], mouseover=[1]}handle=function()
</li>
<li>
<div class="mailval" title="Breast > Right" originaltitle="Breast > NULL > Right">Right</div>events=Object { click=[1], mouseover=[1]}handle=function()
</li>
</ul>
</li>
</ul>
</li>
</ul>
<div style="clear:both"></div>
</div>
<p id="bodypart-error" class="errorMessage ml161px pa ie7ErrorFix" style="top:140px !important"></p>
</div>

最佳答案

在选择器中使用类属性的正确方法是,它应该前面有“.”

你的选择器可以重写如下,

div[title='Breast > Both'].mailval

您也可以试试这个选择器,id 属性应该前面有“#”

#bodyPartList_1 > div div[title='Breast > Both'].mailval

refer this to learn more about selectors

编辑:根据您的 html,弹出窗口仅在悬停或单击时出现。可以使用 JavascriptExecuter 执行此操作,

((JavascriptExecutor)driver).executeScript("$('#bodyPartList_1 > .mailval.fly').click();");

现在将显示弹出窗口,您只需选择所需的值...

new WebDriverWait(driver,20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[title='Breast > Both'].mailval"))).click();

关于java - 无法从类似于下拉框的弹出窗口中选择值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19921702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com