How to select value from a Dropbox list when site html has no select

Asked

Viewed 23 times

-1

Hello!

First, excuse my 'technical' little vocabulary, I’m just an adventurer starting Python learning.

Regarding my problem, I’ve seen some topics both here and in English but all treat in a similar way, like this:

from selenium import webdriver
from selenium.webdriver.support.ui import Select

driver = webdriver.Firefox()
driver.get('url')

select = Select(driver.find_element_by_id('fruits01'))

# select by visible text
select.select_by_visible_text('Banana')

# select by value 
select.select_by_value('1')

However, when I try to apply this to the site I want, his Dropbox list is not done with select in his html, so the error saying that you cannot use this command for this situation.

I can click the button with his xpath, which opens the list with all values (from 1 to 90 - 'minutes of a football game'), but I cannot select any of these items. Each of these list values changes the page outputs, such as scoring, goal kicks, etc.

When I inspect the values of the button, their values are below the html, but I can’t find them even with the xpath, the error in the compilation saying that it does not, even if I click on it with a time.Leep() to load the page it does not find.

The html snippet from the button is in these images:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

And the options go up to number 90, as said above.

Is there any way to click on an item from that list, other than by the select command? Or is there any way to use select even on this site?

I’ve been able to discover several new things looking at forums but this really caught me in the last two days and I still have no solution.

I’d like to thank you in advance and if you’d like any more information, just let me know.

1 answer

0


I finally managed to solve

If anyone ever has this problem too, follow the solution I found by digging into all kinds of python site/foruns:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
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.action_chains import ActionChains
import time

droplist = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="root"]/div/section/section/main/div/div/div[2]/div/div/div[1]/div/div' ))) #encontrar botao da droplist (nesse caso achei melhor com xpath, site mal montado)
ActionChains(driver).move_to_element(droplist)
driver.execute_script('arguments[0].click();', droplist)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'li.ant-select-dropdown-menu-item')))

drop_down_click = wait.until(EC.element_to_be_clickable((By.XPATH, '//li [text()="20"]')))
drop_down_click.click()

This following the HLTM of the site I posted on images, to select the 20th minute of a game, but it could be any text of this combobox droplist that was not mounted with select in html. In the second posted image are the options of this droplist, from 1 to 90... in the case above it would select the 20th minute. I just posted an excerpt from the program of this specific solution.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.