尽管使用id
,但我找不到输入元素。我已经尝试过CssSelector
,Xpath
,Id
。为什么不能这样处理这个元素?
我尝试过:
By id = By.Id("First name:input");
By xpath = By.Xpath("//*[@id=\\"First name:input\\"]");
By selector = By.CssSelector("#First\\ name\\:input");
我使用explict wait
等待输入元素。
输入元素:
<div class="controlPaddingWrapper">
<label id="First name:">First name:</label>
<input ng-attr-id="{{ c.Prompt+ 'input' }}" next-focus="" focus-if="true" class="k-textbox ng-pristine ng-empty ng-invalid ng-invalid-required ng-valid-pattern flow-required ng-touched" pattern=".+$" ng-model="c.Value" ng-class="{'flow-required': isRequired(c)}" required="" style="width: 100%;" ng-change="onChange(c)" id="First name:input" type="text">
</div>
答案 0 :(得分:0)
仅尝试:By id = By.Id("First name");
答案 1 :(得分:0)
您可以使用:
By xpath = By.Xpath("//input[@id='First name:input']");
By selector = By.CssSelector("input[id='First name:input']");
答案 2 :(得分:0)
根据 HTML ,您共享了在所需元素上调用Click()
/ SendKeys()
的功能,因为该元素是您需要指示的Angular元素 WebDriverWait ,使元素可点击,您可以使用以下任一解决方案:
CssSelector
:
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input.k-textbox.ng-pristine.ng-empty.ng-invalid.ng-invalid-required.ng-valid-pattern.flow-required.ng-touched[id*='First']"))).Click();
XPath
:
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@class='k-textbox ng-pristine ng-empty ng-invalid ng-invalid-required ng-valid-pattern flow-required ng-touched' and @id=\"First name:input\"]"))).Click();
答案 3 :(得分:0)
尝试一下:
<label
id="First_name">
By.id("First_name")
By.Xpath("//*[@id='First_name']")
或
By.Xpath("//label[@id='First_name']")
或By.Xpath("//label[contains(text(), 'First name:')]")
有关Xpath的参考,您可以在这里https://www.guru99.com/xpath-selenium.html 抱歉,CssSelector从未使用
<div class="controlPaddingWrapper">
<label id="First name:">First name:</label>
<input ng-attr-id="{{ c.Prompt+ 'input' }}" next-focus="" focus-if="true" class="k-textbox ng-pristine ng-empty ng-invalid ng-invalid-required ng-valid-pattern flow-required ng-touched" pattern=".+$" ng-model="c.Value" ng-class="{'flow-required': isRequired(c)}" required="" style="width: 100%;" ng-change="onChange(c)" id="First name:input" type="text">
</div>