I need to find a specific city from a drop down list. I have tried using the xpath but the id number for the city keeps changing. The element from the website is below:

 <mat-option role="option" class="mat-option mat-focus-indicator mat-active ng-tns-c88-11 ng-star-inserted mat-selected" id="mat-option-14" tabindex="0" aria-disabled="false" style="" aria-selected="true"><!----><span class="mat-option-text"> Melbourne </span><!----><div mat-ripple="" class="mat-ripple mat-option-ripple"></div></mat-option>

My code:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH,'//*[@id="mat-option-14"]/span'))).click()

The code works only when the id is 14 but it can be any number. Can I select by the city name instead somehow? THanks


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.