Issue
I am trying to select a dropdown box. The code from the page is:
<span class="sui-dropdown" tabindex="0" style="width: 150px;">
<select class="dropdown-soberanos-plazo" style="display: none;">
<option value="CI">CI</option><option value="24hs">24hs</option>
<option value="48hs">48hs</option>
</select>
<span class="sui-input sui-unselectable" unselectable="on">48hs</span>
<span class="sui-caret-container sui-unselectable" unselectable="on">
<span class="sui-caret sui-unselectable" unselectable="on">
</span></span></span>
I tried the next code, but i am not even able to select the dropdown.
from selenium.webdriver.support.select import Select
driver.find_elements(By.XPATH,'//*[@id="soberanos"]/div/div[3]/span')
Out[176]: [<selenium.webdriver.remote.webelement.WebElement (session="f181c2e9094dce7159f3b24212735c16", element="8846fda9-7cbe-4b20-ae8c-6b6071f7a18f")>]
Select(driver.find_elements(By.XPATH,'//*[@id="soberanos"]/div/div[3]'))
Traceback (most recent call last):
File "C:\Users\XXXXXXX\AppData\Local\Temp\ipykernel_22996\2906900798.py", line 1, in <cell line: 1>
Select(driver.find_elements(By.XPATH,'//*[@id="soberanos"]/div/div[3]'))
File "C:\Users\XXXXXX\Desktop\Selenium\lib\site-packages\selenium\webdriver\support\select.py", line 36, in __init__
if webelement.tag_name.lower() != "select":
AttributeError: 'list' object has no attribute 'tag_name'
and
from selenium.webdriver.support.ui import Select
with no success :(
I tried with diferents XPATH, same result.
Select(driver.find_elements(By.XPATH,'//*[@id="soberanos"]/div/div[3]/span/select'))
Traceback (most recent call last):
File "C:\Users\ltaboada\AppData\Local\Temp\ipykernel_22996\1364519513.py", line 1, in <cell line: 1>
Select(driver.find_elements(By.XPATH,'//*[@id="soberanos"]/div/div[3]/span/select'))
File "C:\Users\ltaboada\Desktop\Selenium\lib\site-packages\selenium\webdriver\support\select.py", line 36, in __init__
if webelement.tag_name.lower() != "select":
AttributeError: 'list' object has no attribute 'tag_name'
So.... any advice? thanks!!! dropdown Image
Solution
From your added code
and HTML
I can give you the idea, try the below Solution.
driver.find_elements
returns list of WebElements
.
It should be driver.find_element
. Note the s
in find_element.
So, the line of code should be like
Select(driver.find_element(By.XPATH,'//*[@id="soberanos"]/div/div[3]'))
Let us know if this does not work for you.
Answered By - Akzy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.