简体   繁体   中英

Can't find input element by Id or XPath

Selenium can't find the input field neither with Id selector nor with XPath selector.

I tried to search for if it's a hidden div or body

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

Here's the source code:

<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 .

Here is the logic that you have to use.

# 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM