Selenium webdriver C#:在标签内的输入文本元素中查找和输入值在本地工作,但在TeamCity上不起作用
我的网页上有标签。单击标签时,将显示“输入文本”字段。离开此元素后,将再次成为标签。我试图单击标签,清除输入文本元素中的文本,并在输入字段中输入文本 单击标签前的html:Selenium webdriver C#:在标签内的输入文本元素中查找和输入值在本地工作,但在TeamCity上不起作用,c#,selenium-webdriver,C#,Selenium Webdriver,我的网页上有标签。单击标签时,将显示“输入文本”字段。离开此元素后,将再次成为标签。我试图单击标签,清除输入文本元素中的文本,并在输入字段中输入文本 单击标签前的html: <tbody _ngcontent-c5=""> <!--bindings={ "ng-reflect-ng-for-of": "[object Object]" }--> <tr _ngcontent-c5=""> <td _ngcontent-c5="" class=
<tbody _ngcontent-c5="">
<!--bindings={
"ng-reflect-ng-for-of": "[object Object]" }-->
<tr _ngcontent-c5="">
<td _ngcontent-c5="" class="check-box" style="border-right:#dcdcdc;">
<input _ngcontent-c5="" name="isSelected" type="checkbox" id="parameter[0].isSelected" data-index="0"></td>
<td _ngcontent-c5="" class="max-width non-editable-cell">All Countries</td>
<td _ngcontent-c5="" class="max-width non-editable-cell">All Store Affluences</td>
<td _ngcontent-c5="" class="med-width non-editable-cell">
<!--bindings={"ng-reflect-ng-if": "true" }-->
<div _ngcontent-c5="" id="parameter[0].planogramNameLabel">Master Range</div>
<!--bindings={}-->
</td>
<tbody _ngcontent-c5=""> <!--bindings={ "ng-reflect-ng-for-of": "[object Object]"
}--><tr _ngcontent-c5="">
<td _ngcontent-c5="" class="check-box" style="border-right:#dcdcdc;">
<input _ngcontent-c5="" name="isSelected" type="checkbox" id="parameter[0].isSelected" data-index="0"></td>
<td _ngcontent-c5="" class="max-width non-editable-cell">All Countries</td>
<td _ngcontent-c5="" class="max-width non-editable-cell">All Store Affluences</td>
<td _ngcontent-c5="" class="med-width non-editable-cell">
<!--bindings={"ng-reflect-ng-if": "false"}-->
<!--bindings={ "ng-reflect-ng-if": "true"}-->
<input _ngcontent-c5="" class="planogram-parameter-input ng-untouched ng-pristine ng-valid" name="planogramName" type="text" ng-reflect-name="planogramName" ng-reflect-model="Master Range" id="parameter[0].planogramName" data-index="0">
</td>
这段代码在我的本地计算机上运行得非常好。当我尝试在TeamCity上运行这些测试时。无法定位PlanogrameElement
请在下面查找错误:
OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素:{“方法”:“id”,“选择器”:“参数[0]。平面图名称”}
(会话信息:chrome=61.0.3163.100)
(驱动程序信息:chromedriver=2.30.477700(0057494ad8732195794a7b32078424f92a5fce41),平台=Windows NT 6.3.9600 x8664)
在penQA.Selenium.Remote.RemoteWebDriver.UnpackantRownerError(响应错误响应)中
在OpenQA.Selenium.Remote.RemoteWebDriver.Execute(stringdrivercommandtoexecute,Dictionary`2参数)
在OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(字符串机制,字符串值)
在Automation_Dunnhumby_Framework.Steps.SpacerRequestSteps.GivineIntersheldepthHelfHeightTotalModsModuleLength shelvespermodule字段中(字符串平面图名称、字符串Sheldepth、字符串shelfheight、字符串totalmods、字符串modulelength、字符串shelvespermodule)在D:\BuildAgent\work\7f925fcfe8130d53\Automation\u Dunnhumby\u Framework\Automation\u Dunnhumby\u Framework\Steps\SpaceRecsRequestSteps.cs中:第53行
位于TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding绑定、IContextManager contextManager、对象[]参数、ITestTracer testTracer、时间跨度和持续时间)
在TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteTestepMatch(BindingMatch匹配,对象[]参数)
位于TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteTEP(IContextManager contextManager,StepInstance StepInstance)
在TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()中
您提供的
HTML
中的几个观察结果:
AUT(测试中的应用程序)
使用Javascript
/
,这在属性中是明确的,例如id=“参数[0]。isSelected”
将显示输入文本字段
。因此,click()
和输入文本字段的呈现之间有一个delta时间差,这在脚本中没有被考虑,就像在您尝试清除()之后的代码块中一样
如下所示的输入文本字段:
action.MoveToElement(planogramNameLabelelement).Click().Build().Perform();
IWebElement planogramNameelement = Driver.FindElement(By.Id(Constants.Ids["PLANOGRAM_NAME"]));
planogramNameelement.Clear();
action.MoveToElement(planogramNameLabelelement).Click().Build().Perform();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement planogramNameelement = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id(Constants.Ids["PLANOGRAM_NAME"]));
planogramNameelement.Clear();
显式推送,即
使用
预期条件作为元素,使输入文本字段可点击如下:
action.MoveToElement(planogramNameLabelelement).Click().Build().Perform();
IWebElement planogramNameelement = Driver.FindElement(By.Id(Constants.Ids["PLANOGRAM_NAME"]));
planogramNameelement.Clear();
action.MoveToElement(planogramNameLabelelement).Click().Build().Perform();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement planogramNameelement = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id(Constants.Ids["PLANOGRAM_NAME"]));
planogramNameelement.Clear();
您提供的HTML
中的几个观察结果:
AUT(测试中的应用程序)
使用Javascript
/
,这在属性中是明确的,例如id=“参数[0]。isSelected”
将显示输入文本字段
。因此,click()
和输入文本字段的呈现之间有一个delta时间差,这在脚本中没有被考虑,就像在您尝试清除()之后的代码块中一样
如下所示的输入文本字段:
action.MoveToElement(planogramNameLabelelement).Click().Build().Perform();
IWebElement planogramNameelement = Driver.FindElement(By.Id(Constants.Ids["PLANOGRAM_NAME"]));
planogramNameelement.Clear();
action.MoveToElement(planogramNameLabelelement).Click().Build().Perform();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement planogramNameelement = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id(Constants.Ids["PLANOGRAM_NAME"]));
planogramNameelement.Clear();
显式推送,即
使用
预期条件作为元素,使输入文本字段可点击如下:
action.MoveToElement(planogramNameLabelelement).Click().Build().Perform();
IWebElement planogramNameelement = Driver.FindElement(By.Id(Constants.Ids["PLANOGRAM_NAME"]));
planogramNameelement.Clear();
action.MoveToElement(planogramNameLabelelement).Click().Build().Perform();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement planogramNameelement = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id(Constants.Ids["PLANOGRAM_NAME"]));
planogramNameelement.Clear();
从TeamCity运行测试的机器是否可能比您的本地PC慢?谢谢您的回复。我将尝试在定位元素之前添加等待。是否可能从TeamCity运行测试的计算机比您的本地PC慢?谢谢您的回复。我将尝试在定位元素之前添加等待。我添加了显式等待,如您在上面的建议中所述。但现在我得到了一个不同的错误。它一直等到显式等待,然后超时。错误:System.InvalidOperationException:未知错误:元素在点(886695)处不可单击。捕获错误:向远程WebDriver服务器请求URL的HTTP请求在60秒后超时。@user8734797很好,因此,我们已经解决了您的实际问题,解决方法是解决NoTouchElementException:没有这样的元素:无法定位元素
。有关新的异常,请参阅此。你能接受答案吗?我在上面的建议中加了明确的等待。但现在我得到了一个不同的错误。它一直等到显式等待,然后超时。错误:System.InvalidOperationException:未知错误:元素在点(886695)处不可单击。捕获错误:向远程WebDriver服务器请求URL的HTTP请求在60秒后超时。@user8734797很好,因此,我们已经解决了您的实际问题,解决方法是解决NoTouchElementException:没有这样的元素:无法定位元素
。有关新的异常,请参阅此。你能接受这个答案吗。