OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Can't select Dropdown option with Selenium using Python

  • Thread starter Thread starter Davit Nadiradze
  • Start date Start date
D

Davit Nadiradze

Guest
Im trying to automatize adding Promocodes to users, but python is getting stuck on choosing promocode type in dropdown menu, it just opens dropdown and freezes

Code:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
import time

# Set up Chrome options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("user-data-dir=C:/Users/Chairte she bozo/AppData/Local/Google/Chrome/User Data")
chrome_options.add_argument("profile-directory=Profile 4")
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

# Setup ChromeDriver with options
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)

# List of customer URLs and corresponding amounts
customer_data = [
    ("https://test/promocodes", 5.1),
]

# Text for promocode purpose
promocode_purpose = "test"

# Function to automate actions on each customer page
def automate_customer_page(url, amount):
    try:
        driver.get(url)
        
        # Wait for the "Give Promocode" button to be clickable and click it
        give_promocode_button = WebDriverWait(driver, 5).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[data-testid="give-promo-button"]'))
        )
        give_promocode_button.click()

        # Wait for the "Promocode type" dropdown to be clickable and click it
        promocode_type_dropdown = WebDriverWait(driver, 5).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[placeholder="Promocode type"]'))
        )
        promocode_type_dropdown.click()
        
        # Wait for the "Product Balance" option to be visible and click it
        product_balance_option = WebDriverWait(driver, 5).until(
            EC.element_to_be_clickable((By.XPATH, '//p[text()="Product Balance"]'))
        )
        product_balance_option.click()

even chatgpt is stuck so any superhumans here to help me? :3

Here is a image where it gets stuck, I dont understand what im doing wrong, maybe something from inspect?
<p>Im trying to automatize adding Promocodes to users, but python is getting stuck on choosing promocode type in dropdown menu, it just opens dropdown and freezes</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
import time

# Set up Chrome options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("user-data-dir=C:/Users/Chairte she bozo/AppData/Local/Google/Chrome/User Data")
chrome_options.add_argument("profile-directory=Profile 4")
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")

# Setup ChromeDriver with options
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)

# List of customer URLs and corresponding amounts
customer_data = [
("https://test/promocodes", 5.1),
]

# Text for promocode purpose
promocode_purpose = "test"

# Function to automate actions on each customer page
def automate_customer_page(url, amount):
try:
driver.get(url)

# Wait for the "Give Promocode" button to be clickable and click it
give_promocode_button = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[data-testid="give-promo-button"]'))
)
give_promocode_button.click()

# Wait for the "Promocode type" dropdown to be clickable and click it
promocode_type_dropdown = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[placeholder="Promocode type"]'))
)
promocode_type_dropdown.click()

# Wait for the "Product Balance" option to be visible and click it
product_balance_option = WebDriverWait(driver, 5).until(
EC.element_to_be_clickable((By.XPATH, '//p[text()="Product Balance"]'))
)
product_balance_option.click()

</code></pre>
<p>even chatgpt is stuck so any superhumans here to help me? :3</p>
<p><a href="https://i.sstatic.net/v8kiQigo.png" rel="nofollow noreferrer">Here is a image where it gets stuck, I dont understand what im doing wrong, maybe something from inspect?</a></p>
 
Top