如何使用Webdriver在BMC Project中执行下拉菜单 [英] How to perform dropdown in BMC Project using Webdriver

查看:70
本文介绍了如何使用Webdriver在BMC Project中执行下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在BMC项目中自动执行下拉功能.尝试了很多选择.这将对我有很大帮助.请帮忙.

I am not able to automate dropdown function in my BMC project. Tried lots of options. This will help me a lot. Please help..

<div id="WIN_0_913111809" class="df arfid913111809 ardbnCustomer Char" arid="913111809" artype="Char" ardbn="Customer" arlbox="0,4,114,17" style="z-index:993;top:2px; left:12px; width:309px; height:21px;" arwindowid="0">
<label id="label913111809" class="label f9" for="x-arid_WIN_0_913111809" style="top: 4px; left: 0px; width: 114px; height: 17px;">Customer*</label>
<textarea id="arid_WIN_0_913111809" class="text sr " cols="20" maxlen="255" style="top:0px; left:119px; width:164px; height:21px;" armenu="COM:CPY:Company=Oper/Cust-Q_ForInteractionCust" mstyle="2" arautoc="2" arautocak="0" arautoctt="400" rows="1" title="" wrap="off"></textarea>
<a class="btn btn3d menu" href="javascript:" style="top:0px; left:288px; width:21px; height:21px;">
<img class="btnimg" src="../../../../resources/images/mt_sprites.gif" alt="Menu for Customer*" title="">
</a>
</div>​

<div class="MenuTableContainer" style="top: 20px;">
<table class="MenuTable" style="width: 386px;" cellspacing="0" cellpadding="0">
<tbody class="MenuTableBody">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<td class="MenuEntryNameHover" nowrap="">AARADHANA</td>
<td class="MenuEntryNoSubHover" arvalue="AARADHANA"></td>
</tr>
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
<tr class="MenuTableRow">
</tbody>
</table>

我的屏幕看起来像

推荐答案

这不是一个选择标记,也不是一个标记.这是一个由tr和td标签构成的附加下拉菜单元素.因此,无法使用Select类.

This is not a select tag and is not designed to be one. It's an additional drop down menu element structured with tr and td tags. So using the Select class will not work.

选择标记的高级结构示例:

Sample high level structure of a select tag:

<select>
    <option>first option</option>
    <option>second option</option>
</select

要解决您的问题,您可以使用以下方法:

To solve your problem, You could simply use this:

driver.findElement(By.xpath("//div[@ardbn='Customer']//textarea")).clear();
driver.findElement(By.xpath("//div[@ardbn='Customer']//textarea")).sendKeys("AARADHANA");

请记住,您输入的文本应该出现在菜单中.输入列表中不存在的值将导致菜单弹出,并且该字段中没有任何值存储,因此单击保存"时会引发错误,因为这是必填字段.

Keep in mind that the text you are entering should be present in the menu. Entering a value that is not present in the list would result in the menu popping up and no value stored in the field, thereby throwing errors when you click on save since this is a mandatory field.

但是,如果您确实要打开菜单并从中选择某项,则必须等待该元素出现并使用以下选项之一:

However if you do want to open the menu and choose something from there, you would have to wait for the element to appear and use one of these:

如果需要在tr上进行点击

If the click needs to be performed on the tr

driver.findElement(By.xpath("//table[@class='MenuTable']//tr[td[.='AARADHANA']]")).click();

如果需要在td上执行点击

If the click needs to be performed on the td

driver.findElement(By.xpath("//table[@class='MenuTable']//tr//td[.='AARADHANA']")).click();

请特别注意,因为 1.可能隐藏了许多带有'MenuTable'类的元素,如果它们在层次结构中位于较高位置,则脚本将失败. 2.如果没有第一个问题,并且您要选择的客户不可见,则必须滚动直到找到该元素,然后再单击.

Be careful with this though, because 1. There may be many elements with the class 'MenuTable' that are hidden and if they are higher up in the hierarchy the script will fail. 2. If the first issue is not present and the customer you're trying to select is not visible you will have to scroll until the element is found before performing a click.

强烈建议使用sendKeys选项.请确保您包含代码段以指示您尝试过的内容.理解相关元素的结构似乎是一个问题.

Highly recommend using the sendKeys option. Please ensure that you include code snippets to indicate what you've tried. This seems to be an issue with understanding the structure of the element in question.

这篇关于如何使用Webdriver在BMC Project中执行下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆