Home > database >  Selenium Driver - finding element with no ID, Name, Xpath, Tag, Class, CSS Selector
Selenium Driver - finding element with no ID, Name, Xpath, Tag, Class, CSS Selector

Time:07-29

I'm working with Python and Selenium, and trying to select a username field to automate login for an application, however, the webdriver's find_element method doesn't want to play nicely with the username field I've found. Below is the object's HTML I need to locate and select, and subsequently enter data into, and note it doesn't have an ID, Name, Tag, Class, or CSS Selector object to directly reference, and the HTML is not XHTML so the XPath option doesn't work. Does anyone have any suggestions as to how I might be able to locate/enter data into this field via Selenium?

<input  type="text" min="" max="" match-data="" placeholder="" title="" ng-disabled="disabled"
ng-required="required" ng-model="textValue" ng-model-options="options || {}" 
ng-keydown="keydown({$event: $event})" tb-enter="modelCtrl.$commitViewValue(); 
onEnter({$event: $event}); triggerEnter()" ng-paste="onPaste()" tb-auto-select="autoSelect" 
tb-focus="focus" ng-focus="onFocus()" tabindex="0" tb-test-id="textbox-username-input" 
autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" ng-trim="true" 
aria-controls="" aria-haspopup="" aria-activedescendant=""
aria-labelledby="textbox-username-label" name="username" required="required">

CodePudding user response:

Try locating it like below:

input_field = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='username']")))
input_field.click()

You will also need the following imports:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
  • Related