简体   繁体   English

如何从使用Selenium Webdriver中的api响应动态启动的下拉列表中选择特定位置?

[英]How to select particular location from the drop down list which is initiated dynamically using api response in selenium webdriver?

Problem Description: 问题描述:

I am trying to automate the filling of the form in which there's a locality dropdown list. 我正在尝试自动填写有地区下拉列表的表单。 I am facing problem in selecting the option which are suggest in the suggestion list. 我在选择建议列表中建议的选项时遇到问题。 The options in the suggestions list are provided by an api response ie its dynamic. 建议列表中的选项由api响应(即动态)提供。 I am not able to select one of the option from the suggested list. 我无法从建议的列表中选择一个选项。

String Locality ="//label[contains(text(),'Locality')]/following-sibling::input";

public void insertData(DataTable str) throws InterruptedException {
    List<List<String>> list = str.asLists(String.class);
    super.identifyElement(locators.xpath, Locality), list.get(1).get(5));// value sendkey= Akurdi;

HTML Element: HTML元素:

<label _ngcontent-c4="" for="Location" class="active">Locality</label>
<input _ngcontent-c4="" autocapitalize="off" autocorrect="off" class="mb-0 ng-valid ng-dirty ng-touched" formcontrolname="locality" placeholder="" spellcheck="off" stype="locality" type="text" ng-reflect-klass="mb-0" ng-reflect-ng-class="[object Object]" ng-reflect-name="locality" ng-reflect-model="Akurdi" autocomplete="off">

Sendkey value form cucumber screnario: Akurdi... Display Input dropdown list UI Sendkey值形式,黄瓜脚本:Akurdi ... 显示输入下拉列表UI

In these cases I am working with these drop-downs as with usual List. 在这些情况下,我将像往常一样使用这些下拉列表。 Clicking on drop-down opening, waiting for drop-down to appear, then iterating in the list of it's elements, searching what I need by name, then clicking on it. 单击下拉菜单,等待下拉菜单出现,然后在其元素列表中进行迭代,按名称搜索我需要的内容,然后单击它。

Solution

        WebDriver driver = new ChromeDriver();

        driver.get("http://connexistech.net/godamwale/warehouse");

        WebElement locality = driver.findElement(By.xpath(".//div[@id='location']//input")); 

        locality.sendKeys("Akrudi");
       //Here at the end [1] can be any item from 1 to 5 since its showing only 5 suggestions all the time
        String xp = "//div[contains(@class, 'pac-container')]//div[contains(@class, 'pac-item')][1]";

        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//div[contains(@class, 'pac-container')]/div[contains(@class, 'pac-item')]")));
        WebElement element = driver.findElement(By.xpath(xp));             

        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("xp")));
        element.click();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用带有 Java 的 Selenium WebDriver 从下拉列表中选择项目? - How to select item from drop down list using Selenium WebDriver with Java? Selenium WebDriver:无法使用webdriver从下拉列表中选择元素 - Selenium WebDriver: Not able to select the element from the drop down list using webdriver 如何使用 selenium 从下拉菜单中选择动态生成的元素? - How do I select element which are dynamically generating from drop down menu using selenium? 无法从Selenium Webdriver的下拉列表中选择隐藏元素 - Not able to select hidden element from drop down list in Selenium Webdriver 无法使用Java从Selenium Webdriver的下拉列表中选择选项 - Not able to select option from drop down list in selenium webdriver with java 如何选择jquery无序下拉列表selenium webdriver - how to select jquery unorderded drop down list selenium webdriver 使用以下命令从Selenium Java Webdriver下拉菜单中选择一个值 - select a value from drop down in selenium java webdriver using 如何使用selenium webdriver java从城市字段的GoIbibo中的自动选择下拉列表中选择一个元素 - how to select an element from autoselect drop down in GoIbibo from city field using selenium webdriver java 如何使用带有Java的Selenium WebDriver从下拉列表中选择一个选项? - How to select an option from a drop-down using Selenium WebDriver with Java? 如何使用Selenium Webdriver从google注册页面的下拉菜单中选择Birthday(Month)? - How to select Birthday(Month) from drop down in the google Sign up page by using Selenium Webdriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM