1

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 class="tb-text-box-input tb-enable-selection ng-pristine ng-empty ng-invalid ng-invalid-required
ng-touched" 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">
Justin123
  • 57
  • 5

1 Answers1

1

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
Barry the Platipus
  • 9,594
  • 2
  • 6
  • 30
  • Thanks, that worked to find both the u/n and pw fields. By chance can you see within this what I'd use for the CSS_Selector value? This is for the sign-in button, doesn't match format with u/n or pw. – Justin123 Jul 28 '22 at 16:53
  • 1
    Try `WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".tb-orange-button.tb-button-login"))).click() ` – Barry the Platipus Jul 28 '22 at 17:20
  • Can I ask how you determined that was the CSS_SELECTOR? My next step is similar, and I can't seem to get it to work using similar logic you used above (.tabToolbarButton.tab-widget.download does not work but follows the logic in the above).
    Download
    – Justin123 Jul 28 '22 at 22:07
  • Try `WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.ID, "download-ToolbarButton"))).click()` – Barry the Platipus Jul 28 '22 at 22:50
  • Hmm, that one didn't work - it raises a time-out exception on that line, like it couldn't locate the actual button. – Justin123 Jul 29 '22 at 13:45