需要有关元素识别的帮助。
Login : http://admin-demo.nopcommerce.com/
uname : admin@yourstore.com
pass : admin
Click > Catalog > Categories > Add New
由于没有唯一标识符,我在识别下面的xpath方面遇到了困难。
xpath to select value for limited to customer roles
xpath to select value for limited to store
您的解释将帮助我学习如何为没有唯一标识符的webelements编写xpath。
仅限于客户角色
<div class="k-multiselect-wrap k-floatwrap" unselectable="on">
<ul id="SelectedCustomerRoleIds_taglist" class="k-reset" unselectable="on" role="listbox"/>
<input class="k-input k-readonly" style="width: 25px" accesskey="" role="listbox" aria-expanded="false" tabindex="0" aria-owns="SelectedCustomerRoleIds_taglist SelectedCustomerRoleIds_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false"/>
<span class="k-icon k-loading k-loading-hidden"/>
</div>
<select id="SelectedCustomerRoleIds" name="SelectedCustomerRoleIds" multiple="multiple" data-role="multiselect" style="display: none;" aria-disabled="false" aria-readonly="false">
<option value="1">Administrators</option>
<option value="2">Forum Moderators</option>
<option value="4">Guests</option>
<option value="3">Registered</option>
<option value="5">Vendors</option>
</select>
仅限商店
<div class="k-multiselect-wrap k-floatwrap" unselectable="on">
<ul id="SelectedStoreIds_taglist" class="k-reset" unselectable="on" role="listbox"/>
<input class="k-input k-readonly" style="width: 25px" accesskey="" role="listbox" aria-expanded="false" tabindex="0" aria-owns="SelectedStoreIds_taglist SelectedStoreIds_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false"/>
<span class="k-icon k-loading k-loading-hidden"/>
</div>
<select id="SelectedStoreIds" name="SelectedStoreIds" multiple="multiple" data-role="multiselect" style="display: none;" aria-disabled="false" aria-readonly="false">
<option value="1">nopCommerce demo store</option>
<option value="2">Sample store 2</option>
</select>
答案 0 :(得分:0)
你应该尝试如下: -
WebDriverWait wait = new WebDriverWait(driver,10);
对于客户角色下拉菜单: -
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("SelectedCustomerRoleIds_taglist"))).click();
Select customers = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("SelectedCustomerRoleIds_taglist"))));
customers.selectByVisibleText("Administrators");
限于商店下拉菜单: -
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("SelectedStoreIds_taglist"))).click();
Select store = new Select(wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("SelectedStoreIds"))));
store.selectByVisibleText("nopCommerce demo store");