Encountering a problem to interact with a weird button which is a combobox (select)

28 Views Asked by At

The problem is, The which I click the button it shows me a dropdown menu but the option elements are not visible in DOM. In this case, how can I solve it ? The website is: https://www.pump.fun/board Here you can see there is a button named sort: bump order. I have attached a picture of it as well. how can I select one option from it with selenium ? I am also open to any other technology that can be used. Thank you so much for you time. here is the picture

1

There are 1 best solutions below

1
Abhay Chaudhary On

You should first find the element corresponding to the button labelled "I'm ready to pump" using and clicks on it to close the dialog which opens n loading the page.Then find the button element that corresponds to the sorting dropdown and click on it.After that Identify all the sorting options shown. Defines the sorting option to be selected as a variable for e.g. "sort: market cap". Iterates through each available sorting option and clicks on the one matching the defined option. Breaks out of the loop once the desired option is selected

Below code will work

import time
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from webdriver_manager.chrome import ChromeDriverManager

# Initialize WebDriver
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.implicitly_wait(10)

url = "https://www.pump.fun/board"
driver.get(url)
wait = WebDriverWait(driver, 20)

pump = driver.find_element(By.XPATH, "//button[text()[contains(.,'ready to pump')]]")
pump.click()
button = driver.find_element(By.XPATH, "//span[text()='sort: bump order']/..")
wait.until(EC.element_to_be_clickable(button))
button.click()
options = driver.find_elements(
    By.XPATH, "//div[@role='option']/span[contains(text(),'sort')]"
)

optionToSelect = "sort: market cap"

for option in options:
    text = option.text
    if text == optionToSelect:
        option.click()
        break

driver.quit()