'I cannot click an item to populate a form using python and selenium
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.
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://docs.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
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Devam Sanghvi |

