0

I am new to both Python and it's my first time trying Selenium. My goal is to automate some tickets I put in at work. I am using Edge and it seems the page is built using angular. I get up to selecting my option, but no matter what I do I cannot select it, I've scoured other posts here on the issue and have tried all the solutions I can find, but it's still not working. Here is a picture of how far I get.

how far I get

Here is my code, what am I doing wrong?

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

s = Service(r"C:\Users\somename\edge\edgedriver_win64\msedgedriver.exe")
o = Options()
# o.add_argument("user-data-dir=C:\\Users\\somename\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default")
# o.add_argument("profile-directory=Profile 1")
web = webdriver.Edge(service=s, options=o)

web.get("somewebsite")

application_input = '//*[@id="s2id_autogen5"]'
application_typed = '//*[@id="select2-chosen-5"]'
# application_typed = '//*[@id="select2-result-label-20"]'
# application_typed = '/html/body/div[1]/section/main/div/div/sp-page-row/div/div/span[1]/div/div/div/div/div/div[2]/div[2]/div/sp-variable-layout/div[2]/div/div[1]/div/div/span/span/div[2]/div/input'
# application_typed = '/html/body/div[1]/section/main/div/div/sp-page-row/div/div/span[1]/div/div/div/div/div/div[2]/div[2]/div/sp-variable-layout/div[2]/div/div[1]/div/div/span/span/div[2]/div/a/span[1]'


WebDriverWait(web, 20).until(EC.element_to_be_clickable((By.XPATH, application_input)))
web.find_element(By.XPATH, value=application_input).send_keys("Sec")
WebDriverWait(web, 20).until(EC.element_to_be_clickable((By.XPATH, application_typed)))
web.find_element(By.XPATH, value=application_typed).send_keys(Keys.ENTER)



# Resources
# https://www.youtube.com/watch?v=YbGAUEjTKg4
# https://exerror.com/deprecationwarning-executable_path-has-been-deprecated-please-pass-in-a-service-object/
# https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/?tabs=python
# https://stackoverflow.com/questions/65184163/edge-automation-with-selenium-credential-required-constantly
# edge://version/
# https://selenium-python.readthedocs.io/locating-elements.html
# https://stackoverflow.com/questions/63677885/how-to-find-xpath-for-search-on-angular-website
# https://stackoverflow.com/questions/1629053/typing-the-enter-return-key-in-selenium
Altaf
  • 399
  • 1
  • 5
  • 15

1 Answers1

0

Below code may solve your problem:

el = WebDriverWait(browser, 30).until(
    EC.presence_of_element_located(
        (By.XPATH, 'Xpath of DropDown'))
)
for option in el.find_elements_by_tag_name('option'):
    if option.text == 'Value which you want to select ':
        option.click()
        break
    else:
        errortext = "Not Match"

It will check each option value with our value and if it match then option will selected

Devam Sanghvi
  • 548
  • 1
  • 5
  • 11
  • unfortunately, the dropdown is not a select nor are the dropdown selections options, they are using angular where selections make div and spans appear and disappear – Altaf Apr 02 '22 at 04:22
  • 1
    Did Enter key work for you?If you press enter key did option is selected?if yes then you can use module keyboard `import keyboard` and `keyboard.press_and_release('enter')` to press enter after written you search value in dropdown – Devam Sanghvi Apr 02 '22 at 04:40
  • import keyboard worked thank you Devam Sanghvi – Altaf Apr 02 '22 at 05:27
  • unfortunately, solution only works some of the time, I tried adding wait, but still fails mostly – Altaf Apr 02 '22 at 05:47
  • If you Provide more detail(url,xpath,etc.) I can help you more efficiently – Devam Sanghvi Apr 02 '22 at 14:23