我正在使用Java和Selenium编写测试。我有一个要点击的元素(下拉菜单)我使用了action.click
,elemnet.clcik
javascript executor
。但是它们不是元素,而是点击窗口的最左上方。
我打开了开发人员工具窗口并检查了我找到元素的xpath并且它是正确的,我的意思是当我复制粘贴在DOM的xpath时它显示元素。为什么他们点击窗口的左上角?
是该元素所在的dom片段:
<div class="verde-form-row workflowTask-row even">
<h1><span class="by-label">Service</span>: Platinum <span class="unitOrLld">(Acres)</span></h1>
<form class="verde-form-fields fieldInfo-fields " data-task="">
<div data-create-with="" class="form-field-wrapper task-create-with">
<div class="select2-container select2-container-multi verde-select2 undefined" id="s2id_autogen11438">
<ul class="select2-choices">
<li class="select2-search-field">
<label for="s2id_autogen11439" class="select2-offscreen"></label>
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input select2-default" id="s2id_autogen11439" placeholder="" style="width: 290px;" aria-activedescendant="select2-result-label-11977"> </li>
</ul>
</div>
<input data-selector="" type="hidden" name="field" value="" tabindex="-1" class="select2-offscreen">
</div>
<div class="create-task-info">
<div class="task-comments">
<input type="text" name="comments" placeholder="Comments" value="">
<button type="button" data-action="cancel">Cancel</button>
</div>
<div class="task-lab">
<div class="form-field-wrapper" data-field-area="">
<input type="number" step="any" min="0" name="field_area" placeholder="Field Area" value="">
<label class="task-field-area-unit" data-field-area-units="">Acres</label>
</div>
<div data-lab-priority="" class="form-field-wrapper">
<div class="select2-container verde-select2 undefined select2-allowclear" id="s2id_autogen12036">
<a href="javascript:void(0)" class="select2-choice" tabindex="-1"> <span class="select2-chosen" id="select2-chosen-12037">Applied (Pre Buy)</span><abbr class="select2-search-choice-close"></abbr> <span class="select2-arrow" role="presentation"><b role="presentation"></b></span>
</a>
<label for="s2id_autogen12037" class="select2-offscreen"></label>
<input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-12037" id="s2id_autogen12037">
<div class="select2-drop select2-display-none select2-with-searchbox">
<div class="select2-search">
<label for="s2id_autogen12037_search" class="select2-offscreen"></label>
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" role="combobox" aria-expanded="true" aria-autocomplete="list" aria-owns="select2-results-12037" id="s2id_autogen12037_search" placeholder=""> </div>
<ul class="select2-results" role="listbox" id="select2-results-12037"> </ul>
</div>
</div>
<input data-selector="" type="hidden" name="lab_priority_type" value="11" tabindex="-1" title="" class="select2-offscreen">
</div>
<div data-lab-analysis="" class="form-field-wrapper"></div>
</div>
</div>
</form>
这是我的xpath:
//div[./h1[contains(text(),'Platinum')]]//span[text()='Applied (Pre Buy)']
提示:当我点击窗口的任何其他部分,然后点击它工作的元素!!!