<legend id='my8sZ'><style id='my8sZ'><dir id='my8sZ'><q id='my8sZ'></q></dir></style></legend>
      • <bdo id='my8sZ'></bdo><ul id='my8sZ'></ul>
    1. <tfoot id='my8sZ'></tfoot>

      <i id='my8sZ'><tr id='my8sZ'><dt id='my8sZ'><q id='my8sZ'><span id='my8sZ'><b id='my8sZ'><form id='my8sZ'><ins id='my8sZ'></ins><ul id='my8sZ'></ul><sub id='my8sZ'></sub></form><legend id='my8sZ'></legend><bdo id='my8sZ'><pre id='my8sZ'><center id='my8sZ'></center></pre></bdo></b><th id='my8sZ'></th></span></q></dt></tr></i><div id='my8sZ'><tfoot id='my8sZ'></tfoot><dl id='my8sZ'><fieldset id='my8sZ'></fieldset></dl></div>

        <small id='my8sZ'></small><noframes id='my8sZ'>

        “消息=未知错误:无法聚焦元素"通过 Selenium、ChromeDriver 和 Chrome 执行测试时

        时间:2023-09-14

        <small id='JDUWB'></small><noframes id='JDUWB'>

                <i id='JDUWB'><tr id='JDUWB'><dt id='JDUWB'><q id='JDUWB'><span id='JDUWB'><b id='JDUWB'><form id='JDUWB'><ins id='JDUWB'></ins><ul id='JDUWB'></ul><sub id='JDUWB'></sub></form><legend id='JDUWB'></legend><bdo id='JDUWB'><pre id='JDUWB'><center id='JDUWB'></center></pre></bdo></b><th id='JDUWB'></th></span></q></dt></tr></i><div id='JDUWB'><tfoot id='JDUWB'></tfoot><dl id='JDUWB'><fieldset id='JDUWB'></fieldset></dl></div>
                  <bdo id='JDUWB'></bdo><ul id='JDUWB'></ul>

                    <tbody id='JDUWB'></tbody>
                • <tfoot id='JDUWB'></tfoot><legend id='JDUWB'><style id='JDUWB'><dir id='JDUWB'><q id='JDUWB'></q></dir></style></legend>
                  本文介绍了“消息=未知错误:无法聚焦元素"通过 Selenium、ChromeDriver 和 Chrome 执行测试时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 google chrome 浏览器中发送下拉列表的密钥,但我收到此错误

                  I am trying to send key for a drop down list in google chrome browser but i am receiving this error

                  OpenQA.Selenium.WebDriverException
                    HResult=0x80131500
                    Message=unknown error: cannot focus element
                    (Session info: chrome=68.0.3440.106)
                    (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
                    Source=WebDriver
                    StackTrace:
                     at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
                     at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
                     at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary`2 parameters)
                     at OpenQA.Selenium.Remote.RemoteWebElement.SendKeys(String text)
                     at BnI.UITests.Register.TheOfficialInfoValidTest() in C:UsersmeUITestsRegister.cs:line 382
                  

                  这是我的方法:

                  driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Country:'])[1]/following::span[2]")).SendKeys("USA");
                  

                  这是它在 html 中的样子:

                  This how its look in html :

                  <div _ngcontent-c4="" class="col-xs-8 no-padding-sides ng-star-inserted" style="">
                     <kendo-dropdownlist _ngcontent-c4="" class="custom-dropdown k-widget k-dropdown k-header ng-pristine ng-invalid ng-touched" formcontrolname="countryId" dir="ltr">
                        <span role="listbox" unselectable="on" class="k-dropdown-wrap k-state-default" id="k-d0697a91-baeb-4960-bfc1-c023903c1159" dir="ltr" readonly="false" tabindex="0" aria-disabled="false" aria-readonly="false" aria-haspopup="true" aria-expanded="false" aria-owns="dbfc0894-a4f5-4f1b-881f-1d88ccdc6002" aria-activedescendant="f65cbfa2-6280-4a84-908b-ba11da75d59d-undefined">
                           <span unselectable="on" class="k-input">
                              <!----><!---->Select Country ...
                           </span>
                           <span unselectable="on" class="k-select"><span class="k-i-arrow-s k-icon"></span></span><!---->
                        </span>
                        <!----><!---->
                     </kendo-dropdownlist>
                  </div>
                  

                  这是 XPath:

                  xpath=(.//*[normalize-space(text()) and normalize-space(.)='Country:'])[1]/following::span[2]
                  

                  如果我想使用 selenium IDE 单击它,下拉列表值的外观是这样的,因为该值是从数据库中检索的:

                  This how dropdownlist value look like if i want to click on it using selenium IDE because this value is retrieved from database :

                  1. 首先我点击下拉列表
                  2. 第二次选择国家

                  是否有另一种方法可以在 selenium 中通过键盘而不是发送键来添加值?

                  Is there another way to add value by keyboard in selenium instead of send key ?

                  推荐答案

                  根据您共享的 HTML,目标元素是 <span> 标记,因此您将无法调用SendKeys() 方法.相反,您需要诱导 WebDriverWait 以使所需元素可点击,并且您可以使用以下任一解决方案:

                  As per the HTML you have shared the target element is a <span> tag so you won't be able to invoke SendKeys() method. Instead you need to induce WebDriverWait for the desired element to be clickable and you can use either of the following solution:

                  new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//span[@class='k-dropdown-wrap k-state-default' and @role='listbox']/span[@class='k-input']"))).Click();
                  //or
                  new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//span[@class='k-dropdown-wrap k-state-default' and @role='listbox']//span[@class='k-select']"))).Click();
                  

                  这篇关于“消息=未知错误:无法聚焦元素"通过 Selenium、ChromeDriver 和 Chrome 执行测试时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:C# Selenium/ChromeDriver 添加用户配置文件首选项 下一篇:无法在 Selenium C# 中获取 Chrome 性能日志

                  相关文章

                  <i id='imhfe'><tr id='imhfe'><dt id='imhfe'><q id='imhfe'><span id='imhfe'><b id='imhfe'><form id='imhfe'><ins id='imhfe'></ins><ul id='imhfe'></ul><sub id='imhfe'></sub></form><legend id='imhfe'></legend><bdo id='imhfe'><pre id='imhfe'><center id='imhfe'></center></pre></bdo></b><th id='imhfe'></th></span></q></dt></tr></i><div id='imhfe'><tfoot id='imhfe'></tfoot><dl id='imhfe'><fieldset id='imhfe'></fieldset></dl></div>
                  • <bdo id='imhfe'></bdo><ul id='imhfe'></ul>
                  <legend id='imhfe'><style id='imhfe'><dir id='imhfe'><q id='imhfe'></q></dir></style></legend>

                    <small id='imhfe'></small><noframes id='imhfe'>

                    <tfoot id='imhfe'></tfoot>