[英]Unable to indentify the element in selenium C#
I am automating one of the commercial application and when I try to identify element using CSS,Xpath, ID, the element is being identified and shows as only one matching node in Firebug, but when I use that element for the test case automation.I see the below error 我正在自动化其中一个商业应用程序,当我尝试使用CSS,Xpath,ID来标识元素时,该元素已被标识并在Firebug中仅显示为一个匹配节点,但是当我将该元素用于测试用例自动化时。看到以下错误
An exception of type 'OpenQA.Selenium.NoSuchElementException' occurred in WebDriver.dll but was not handled in user code WebDriver.dll中发生类型'OpenQA.Selenium.NoSuchElementException'的异常,但未在用户代码中处理
Please find the below html code for the application 请为应用找到以下html代码
<div id="QueryOption1" class="SelectedDiv" xmlns:local="#local-functions" xmlns:msxsl="urn:schemas-microsoft-com:xslt" name="QueryOptions">
<span>
<div>
<div class="leftSide">Subscriber ID: </div>
<input id="Subscriber_ID" class="floatLeft" type="text" name="InsuranceNum" size="15"/>
</div>
Below is the options that I have tried 以下是我尝试过的选项
By.id("Subscriber_First_Name") By.id(“ Subscriber_First_Name”)
By.CssSelector("#QueryOption1 > div > #Subscriber_Last_Name") By.CssSelector(“#QueryOption1> div> #Subscriber_Last_Name”)
By.Xpath("//input[@id='Subscriber_First_Name']") By.Xpath(“ // input [@ id ='Subscriber_First_Name']”)
By.CssSelector("input[id=Subscriber_First_Name][type=text]") By.CssSelector(“ input [id = Subscriber_First_Name] [type = text]”)
None of them worked for me to pass the value into the text box.PLease kindly help 他们都不适合我将值传递到文本框中。请帮忙
why are you using id as :- Subscriber_First_Name while in your above HTML "id" is:- 为什么在上面的HTML“ id”中,将id用作:-Subscriber_First_Name:-
By.id("QueryOption1") // for first div
By.id("Subscriber_ID") //for input tag
By.xpath("//input[@id='Subscriber_ID']")
OR you can use name locator also 或者您也可以使用名称定位器
By.name("QueryOptions")
By.name("InsuranceNum")
OR can set the value using JavascriptExecutor 或者可以使用JavascriptExecutor设置值
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("$('#Subscriber_ID').attr('value','user')");
you can get it using IJavaScriptExecuter 您可以使用IJavaScriptExecuter获取它
IJavaScriptExecutor jsExc = browser as IJavaScriptExecutor;
string textValue = jsExc.ExecuteScript("return document.getElementById('Subscriber_ID').value;").ToString();
I'm confused as to why the HTML you provided shows the id for the INPUT as Subscriber_ID and you are using Subscriber_First_Name in your code examples. 我对您提供的HTML为什么将INPUT的ID显示为Subscriber_ID以及您在代码示例中使用Subscriber_First_Name感到困惑。 That could be the issue but you didn't provide the actual code you are using so I'm not sure.
可能是问题所在,但您没有提供实际使用的代码,所以我不确定。
Try this 尝试这个
driver.FindElement(By.Id("Subscriber_ID")).SendKeys("some text goes into the text box");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.