我想從selenium的以下表單中選擇輸入字段。我嘗試了很多方法,但沒有找到任何幫助,我的測試總是失敗。 這裏是HTML表單:從selenium的html表單中選擇輸入字段
`<form class="login" action="/Index/trylogin/?ru=L015RmlueWE=" novalidate>
<fieldset>
<label>
<input type="text" maxlength="14" tabindex="1" value="" placeholder="Pseudonym">
</label>
<label>
<input type="password" maxlength="20" tabindex="2" data-ch="8H7vtP9f9tns3TGMJ6F995kTyLSmwFsdDlIyBLhBBsrrW1ZHIZiec4cPqF7C5sp5" data-ch2="1782447a8c3759d4407ed522b831806e8cfde5dc" placeholder="Kennwort">
</label>
<input type="submit" value="Anmelden" class="button button-style1">
<div class="login-options">
<label>
<input type="checkbox" value="1" name="stayon">Automatisch anmelden (auf diesem Gerät)
</label>
</div>
</fieldset>
</form>`
她是我的測試方法
[TestMethod]
public void Login_FinYa_System()
{
IWebElement login = _driver.FindElement(By.XPath("//form[1]"));
IWebElement pass = _driver.FindElement(By.XPath("//form[2]"));
login.Click();
login.SendKeys("helo");
pass.Click();
pass.SendKeys("123");
pass.SendKeys(Keys.Enter);
Assert.AreEqual("hello", "hello");
}
它不工作我試過了。這裏是另一種方法,我已經嘗試過_driver.FindElement(By.XPath(「// form [@ class ='login']/input [1]」))'它不工作 – Amjad
輸入不是直接子對象表單標籤。試試這個 - // form [@ class ='login'] // input [1] – Ankur
,這也是行不通的。 – Amjad