Reputation:
I want to automate the account registration on https://outlook.live.com/owa/
I came as far as here:
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'
!
Upvotes: 1
Views: 159
Reputation: 33384
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')
Upvotes: 1