无法通过ID或XPath查找输入元素

时间:2019-07-25 18:30:49

标签: c# html angular selenium selenium-webdriver

硒既无法使用Id选择器,也无法使用XPath选择器来找到输入字段。

我试图搜索它是隐藏的div还是body

webDriver.FindElement(By.XPath("//*[@id='64inputText']")).SendKeys(cnpj);
webDriver.FindElement(By.Id("64inputText")).SendKeys(cnpj);

这是源代码:

<input id="64inputText" name="64inputText" type="text" class="form-control pd-input-size ng-valid-pattern ng-valid-minlength ng-valid-maxlength ng-valid-cpf ng-valid-cnpj ng-not-empty ng-dirty ng-valid-parse ng-valid ng-valid-required ng-touched" ng-model="ngModel" ng-required="ngRequired" ng-change="onChange($event)" ng-blur="onBlur($event)" ng-cut="naoPermitirCortar === true ? $event.preventDefault() : ngCut()" ng-copy="naoPermitirCopiar === true ? $event.preventDefault() : ngCopy()" ng-paste="naoPermitirColar === true ? $event.preventDefault() : ngPaste()" ng-disabled="ngDisabled" ng-readonly="ngReadonly" placeholder="" maxlength="500" minlength="" pd-maiusculo="::maiusculo" required="required" aria-invalid="false" style="">

and the link

1 个答案:

答案 0 :(得分:0)

这是您必须使用的逻辑。

# switch to the first iframe
driver.switch_to.frame(driver.find_elements_by_xpath("//iframe")[0])
# then interact with the field (Make sure you enter only numeric in this field)
driver.find_element_by_xpath("//input[@id='61inputText']").send_keys("12345678901")
# Don't forget to switch to parent window once you are done with actions on iframe using below
driver.switch_to.default_content()