0

I'm trying to fill in some form, but can't access the field with selenium. I searched for some answers, but none of them worked. What do i do?

It's for a bot that I'm working with python and selenium

Here is the code of the bot that fill the form:

def fillEmailAndName():
    input_name = DRIVER.find_element_by_id('contestant[name]')
    input_name.send_keys(DATA['name'])

    input_email = DRIVER.find_element_by_id('contestant[email]')
    input_email.send_keys(DATA['email'].format(generateEmailNumber()))

    input_email.send_keys(Keys.ENTER)

And here is the element name on html:

input id="contestant[name]" name="name" ng-model-options="{ debounce: 300 }" ng-model="contestantState.form.name" ng-pattern=".*" placeholder="Alice Smith" required="" style="width: 246px" type="text" class="ng-empty ng-invalid ng-invalid-required ng-valid-pattern ng-dirty ng-valid-parse ng-touched"

And her the element email:

input id="contestant[email]" name="email" ng-change="contestantState.failedEmail = nil" ng-model-options="{ debounce: 300 }" ng-model="contestantState.form.email" pattern="[A-Z0-9._%a-z\-+]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,12}" placeholder="alice.smith@example.com" required="" style="width: 246px; -webkit-appearance: none;" type="email" class="ng-empty ng-valid-email ng-invalid ng-invalid-required ng-valid-pattern ng-dirty ng-touched"

this is the error that are giving me:

selenium.common.exceptions.ElementNotInteractableException: Message: Element input id="contestant[name]" class="ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required ng-valid-pattern" name="name" type="text" is not reachable by keyboard

Page Source:

form class="contestant compact-box form-compact ng-scope ng-invalid ng-invalid-required ng-valid-pattern ng-valid-email ng-dirty ng-valid-parse" name="contestantForm" ng-init="initFacebook()"

fieldset class="center ng-hide" ng-show="(!contestantState.emailLogin && !campaign.details_first && campaign.login_first && !contestantState.contestant.id) || socialLoginRequired()"

p style="margin-top: 15px" class="ng-binding"

Log in using...

/p

div class="center login-choice login-types-5"

ul

!-- ngRepeat: provider in ::campaign.login_types --li ng-repeat="provider in ::campaign.login_types" class="ng-scope"

a class="no-underline email-background popup-window" data-track-event="###APP_NAME### Login|email" href="javascript:void(0)" ng-click="openAuthentication(provider)" uib-tooltip="Email"

i class="fa fa-envelope-o"/i

span class="login-block--prefix"Login with/span

span class="login-block--text ng-binding"

Email

/span

/a

/li!-- end ngRepeat: provider in ::campaign.login_types --li ng-repeat="provider in ::campaign.login_types" class="ng-scope"

a class="no-underline facebook-background popup-window" data-track-event="###APP_NAME### Login|facebook" href="javascript:void(0)" ng-click="openAuthentication(provider)" uib-tooltip="Facebook"

i class="fa fa-facebook"/i

span class="login-block--prefix"Login with/span

span class="login-block--text ng-binding"

Facebook

/span

/a

/li!-- end ngRepeat: provider in ::campaign.login_types --li ng-repeat="provider in ::campaign.login_types" class="ng-scope"

a class="no-underline instagram-background popup-window" data-track-event="###APP_NAME### Login|instagram" href="javascript:void(0)" ng-click="openAuthentication(provider)" uib-tooltip="Instagram"

i class="fa fa-instagram"/i

span class="login-block--prefix"Login with/span

span class="login-block--text ng-binding"

Instagram

/span

/a

/li!-- end ngRepeat: provider in ::campaign.login_types --li ng-repeat="provider in ::campaign.login_types" class="ng-scope"

a class="no-underline soundcloud-background popup-window" data-track-event="###APP_NAME### Login|soundcloud" href="javascript:void(0)" ng-click="openAuthentication(provider)" uib-tooltip="Soundcloud"

i class="fa fa-soundcloud"/i

span class="login-block--prefix"Login with/span

span class="login-block--text ng-binding"

Soundcloud

/span

/a

/li!-- end ngRepeat: provider in ::campaign.login_types --li ng-repeat="provider in ::campaign.login_types" class="ng-scope"

a class="no-underline twitter-background popup-window" data-track-event="###APP_NAME### Login|twitter" href="javascript:void(0)" ng-click="openAuthentication(provider)" uib-tooltip="Twitter"

i class="fa fa-twitter"/i

span class="login-block--prefix"Login with/span

span class="login-block--text ng-binding"

Twitter

/span

/a

/li!-- end ngRepeat: provider in ::campaign.login_types --

/ul

/div

/fieldset

fieldset class="inputs" ng-show="!socialLoginRequired() && (!campaign.login_first || contestantState.emailLogin || campaign.details_first || (contestantState.contestant.id && requiresInitialLogin()) || contestantState.unconfirmed || (entry_method && entry_method.always_require_email && !contestantState.contestant.email))"

div class="center details-header" ng-switch="::isReward()"

!-- ngSwitchWhen: true --

!-- ngSwitchWhen: false --div ng-switch-when="false" class="ng-scope"

!-- ngIf: campaign.additional_contestant_details && contestantStep==0 --

!-- ngIf: ::!campaign.additional_contestant_details --div ng-if="::!campaign.additional_contestant_details" class="ng-scope"

!-- ngIf: ::campaign.login_first --

!-- ngIf: ::!campaign.login_first --h4 ng-if="::!campaign.login_first" class="ng-binding ng-scope"In order to contact you we need an email/h4!-- end ngIf: ::!campaign.login_first --

/div!-- end ngIf: ::!campaign.additional_contestant_details --

/div!-- end ngSwitchWhen: --

/div

div class="form-horizontal"

div ng-init="contestantSteps=1"

!-- ngIf: contestantStep==0 --div class="contestant-form-group ng-scope" ng-if="contestantStep==0"

div class="input required stringish form-group error" ng-class="{error: contestantForm.name.$invalid && contestantForm.name.$dirty, success: contestantForm.name.$valid}"

label class="control-label" for="contestant[name]"Full Name/label

div class="form-wrapper"

input id="contestant[name]" name="name" ng-model-options="{ debounce: 300 }" ng-model="contestantState.form.name" ng-pattern=".*" placeholder="Alice Smith" required="" style="width: 246px" type="text" class="ng-empty ng-invalid ng-invalid-required ng-valid-pattern ng-dirty ng-valid-parse ng-touched"

div class="help-inline" ng-hide="contestantForm.name.$viewValue"Required/div

/div

/div





div class="email input required stringish form-group" ng-class="{error: ((contestantState.form.email && contestantState.form.email == contestantState.failedEmail) || (contestantForm.email.$invalid && contestantForm.email.$dirty)), success: contestantState.form.email != contestantState.failedEmail && contestantForm.email.$valid}"

label class="control-label" for="contestant[email]"Email/label

div class="form-wrapper"

input id="contestant[email]" name="email" ng-change="contestantState.failedEmail = nil" ng-model-options="{ debounce: 300 }" ng-model="contestantState.form.email" pattern="[A-Z0-9._%a-z\-+]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,12}" placeholder="alice.smith@example.com" required="" style="width: 246px; -webkit-appearance: none;" type="email" class="ng-pristine ng-untouched ng-empty ng-valid-email ng-invalid ng-invalid-required ng-valid-pattern"

div class="help-inline" ng-hide="contestantForm.email.$viewValue"Required/div

div class="help-inline error ng-binding ng-hide" ng-show="contestantState.form.email && contestantState.form.email == contestantState.failedEmail"



/div

/div

/div





/div!-- end ngIf: contestantStep==0 --

/div

/div

!-- ngIf: contestantStep==0 --div class="contestant-form-group ng-scope" ng-if="contestantStep==0"

div class="boolean input optional form-group" ng-hide="::isReward() || !campaign.show_competition_subscription"

div class="form-wrapper"

label class="checkbox ng-binding"

span class="icon"/span

span class="icon-to-fade"/span

input ng-model="contestantState.form.competition_subscription" type="checkbox" class="ng-pristine ng-untouched ng-valid ng-empty"

Notify me of other Jessicamb Competitions

(optional)

/label

/div

/div

!-- ngIf: ::campaign.facebook_url --

/div!-- end ngIf: contestantStep==0 --

/fieldset

div class="form-actions center" ng-show="(!campaign.login_first || contestantState.emailLogin || campaign.details_first || contestantState.contestant.id) && !socialLoginRequired()"

span style="position: inline-block; position: relative"

!-- ngIf: nextStepAvailable() --

!-- ngIf: !nextStepAvailable() --button class="btn btn-primary ng-scope" ng-click="setContestant()" ng-disabled="contestantForm.$invalid || contestantState.sending" ng-if="!nextStepAvailable()" disabled="disabled"

span class="fa fa-refresh fa-spin ng-hide" ng-show="contestantState.sending"/span

!-- ngIf: ::campaign.login_first --

!-- ngIf: ::!campaign.login_first --span ng-if="::!campaign.login_first" class="ng-scope"Save/span!-- end ngIf: ::!campaign.login_first --

/button!-- end ngIf: !nextStepAvailable() --

span ng-show="contestantButtonTooltip(contestantForm.$valid)" style="position: absolute; z-index: 1; top: 0; bottom: 0; left: 0; right: 0" tooltip-placement="top" uib-tooltip="Please complete your details to continue"/span

/span

span ng-hide="::campaign.login_first && campaign.details_first"

a href="javascript:void(0)" ng-click="cancelEntry('###APP_NAME### Click|Cancel|Contestant')"

Cancel

/a

/span

/div

/form

i don't know how to put html arrows without stackoverflow hitching

CAIO WANDERLEY
  • 313
  • 2
  • 9

1 Answers1

0

You can try to set it from javascript:

DRIVER.execute_script("document.querySelector('[name=name]').value = 'xxx'")

That will work even when the input is not interactable.

pguardiario
  • 53,827
  • 19
  • 119
  • 159
  • So, what this '[name=name]' it's, because i saw that this field it's for some css selector like the class. That is it? And if it is why its not '.contestant[name]', wich is the class name? And what is 'xxx'? – CAIO WANDERLEY Aug 05 '19 at 23:01
  • The first input has a name attribute whose value is name, . xxx is whatever you want to set the value to. – pguardiario Aug 05 '19 at 23:23
  • so i set the value, then its just get the element by this value right? – CAIO WANDERLEY Aug 05 '19 at 23:27
  • didn't work. But i don't how to insert my code here. this is the error: selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //input[@name='my_name_to_insert']. And this was how i did: DRIVER.execute_script("document.querySelector('[name=name]').value = 'my_name_to_insert'") input_name = DRIVER.find_element_by_xpath("//input[@name='my_name_to_insert'") input_name.send_keys(DATA['name']) – CAIO WANDERLEY Aug 05 '19 at 23:58