Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Select Value In Selenium

I want to automate the account registration on https://outlook.live.com/owa/

I came as far as here:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I couldn’t use from selenium.webdriver.support.ui import Select to select either outlook.com or hotmail.com from the dropdown menu.

I tried:

Select(driver.find_element(By.CSS_SELECTOR, 'select')).select_by_value('hotmail.com')

My Error:

Traceback (most recent call last):

  File "C:\Users\Administrator\Desktop\outlook\start.py", line 13, in <module>
    create_email(settings, driver)

  File "C:\Users\Administrator\Desktop\outlook\bot\create_email.py", line 14, in create_email
    Select(driver.find_element(By.CSS_SELECTOR, 'select')).select_by_value('hotmail.com')

  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\support\select.py", line 87, in select_by_value
    raise NoSuchElementException("Cannot locate option with value: %s" % value)

selenium.common.exceptions.NoSuchElementException: Message: Cannot locate option with value: hotmail.com

HTML code of the site:

<select class="phoneCountry col-xs-24 win-dropdown" id="LiveDomainBoxList" name="LiveDomainBoxList" aria-label="Email domain options" data-bind="options: domains, value: domain, hasFocus: isLiveDomainDropDownFocused, disable: memberName.isValidating(), css: {'win-dropdown': config.isWin10HostOOBEDesktop !== 0}">
    <option value="outlook.com">outlook.com</option>
    <option value="hotmail.com">hotmail.com</option>
</select>

EDIT:

Instead of By.CSS_SELECTOR, 'select'

I used By.XPATH, '//*[@id="LiveDomainBoxList"]'

and it’s working. But I still want to use By.CSS_SELECTOR, 'select'!

>Solution :

if you want use by css selector use the same id to identify the element.

Select(driver.find_element(By.CSS_SELECTOR, '#LiveDomainBoxList')).select_by_value('hotmail.com')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading