【问题标题】:Not able to write new Fields in Text box area无法在文本框区域写入新字段
【发布时间】:2020-03-10 07:26:08
【问题描述】:

我正在尝试在航班搜索应用程序 (https://flights.msn.com/en-in/flight-search) 的 Origin 位置写入任何新字段,但无法写入。我尝试了所有可能的 XPath 和定位器,但都做不到。

Origin Place 中的默认值是不删除,不允许写入任何新字段。

链接https://flights.msn.com/en-in/flight-search

字段:原点

错误

线程 "main" org.openqa.selenium.NoSuchElementException 中的异常:没有这样的元素:无法找到元素:{"method":"xpath","selector":"//div[@class='js- originplace field-box flex']"} (会话信息:chrome=80.0.3987.132)

代码

<div class="js-originplace field-box flex"><div class="place-selector js-place-selector">
        <div class="place-selector__root clearfix">
            <a href="#" tabindex="1" class="place-selector__cover text-ellipsis js-autocomplete-place-cover populated">Bengaluru <span class="place-selector__cover-id">(Any)<span></span></span></a>
            <div class="place-selector__content">
                <input class="place-selector__input js-place-input" size="1" tabindex="1" type="text" placeholder="Origin city or airport" autocomplete="off" value="">
                <div class="place-selector__loading-spinner js-loading js-spin-activated" style="display: none;">
                <div class="place-selector__dropdown dropdown">
                    <div class="place-selector__not-found js-not-found" style="display: none;">
                        <div data-i18n="search.place.not-found">Type a city or airport</div>
                    </div>
                    <ul class="dropdown-items js-dropdown-items"></ul>
                </div>
            </div>
        </div>
    </div></div>

【问题讨论】:

    标签: selenium xpath


    【解决方案1】:

    尝试使用 element.click 字段,然后使用清除发送键发送您的输入。

    【讨论】:

      【解决方案2】:

      试试这个 xpath:

      //*[@class='js-originplace field-box flex']/descendant-or-self::a
      

      选项 2

      WebElement element = driver.findElement(By.xpath("//*[@class='js-originplace field-box flex']/descendant-or-self::a"));
      JavascriptExecutor js= (JavascriptExecutor)driver;
      js.executeScript("arguments[0].click();", element);
      

      【讨论】:

      • 上述 xpath 出现“线程“主”org.openqa.selenium.InvalidElementStateException:无效元素状态(会话信息:chrome=80.0.3987.132)中的异常
      • 试试 javascriptexecutor。我已经用那个选项更新了我的答案
      猜你喜欢
      • 2021-11-16
      • 2012-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-20
      相关资源
      最近更新 更多