What is the process for clicking a button in Selenium Python that lacks a "select" tag and only becomes clickable after fulfilling certain conditions?

Currently, I am working on automating the process of downloading files. To locate these files, I need to interact with two dropdown menus: one named 'Select Period' where I choose a date, and the other named 'Select File Type' where I select 'All Types'. Interestingly, the HTML code does not have a select tag, but I am able to achieve this using Class Name attribute. However, my challenge arises when I attempt to click on a button labeled 'Start Report'. This button only becomes clickable once values are chosen from both dropdowns.

I have attempted the following code:

start_report_button = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "//p[@class='mud-typography mud-typography-body1' and text()='Start Report']"))
)

driver.execute_script("arguments[0].scrollIntoView(true);", start_report_button)

start_report_button.click()

Unfortunately, this code did not work as expected. For further reference, here is some additional information about the HTML structure: view image view image view image

Answer №1

Your explanation lacked specifics regarding the 'Start Report' button, but typically, buttons are not enclosed within a <p> tag.

Consider checking for elements such as <button> or <a> tags above the <p> tag that may represent your button instead.

Relying solely on class names in locators is not advisable, as they frequently change over time.

If the 'Start Report' button is hidden from view, you can utilize ActionChains to navigate to it. Before implementing the code provided below, verify the locator of the target button.

def select_from_dropdown(wait, dropdown_locator, value_locator):
    wait.until(EC.presence_of_element_located((By.XPATH, dropdown_locator))).click()
    wait.until(EC.element_to_be_clickable((By.XPATH, value_locator))).click()


driver = get_driver("chrome")
wait = WebDriverWait(driver, 10)
actions = ActionChains(driver)

# go to the specified page
driver.get("your_page_url")

# choose period
select_from_dropdown(wait, "your_select_period_dropdown_xpath", "your_select_period_dropdown_value_xpath")
# choose file type
select_from_dropdown(wait, "your_select_type_dropdown_xpath", "your_select_type_dropdown_value_xpath")

# ensure the visibility of the button
start_report_btn = wait.until(EC.visibility_of_element_located((By.XPATH, "//p[text()='Start Report']")))

# move to and click the button
actions.move_to_element(start_report_btn).click(start_report_btn).perform() 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error encountered when attempting to convert 3D numpy array into mesh: RuntimeError - Unable to locate a surface with the specified iso value

I have developed a deep learning model to segment CT scans. The process involves reading the scan as a .nrrd file in python and converting it to a numpy array for training the model. After successfully predicting a numpy array with the model, I encounter ...

The Python program continues running after it's created

Executing the all.py program: import subprocess import os scripts_to_run = ['AppFlatForRent.py','AppForSale.py','CommercialForSale.py','LandForSale.py','MultipleUnitsForSale.py','RentalWanted.py&apos ...

Guide to easily printing a page in Angular 4 using TypeScript

When using my web app, there are certain pages where I need to print only a specific component without including the sidebar. I have written the following TypeScript code to achieve this: print() { window.print(); } The relevant HTML code begins with: & ...

Using Python's Matplotlib library to display an image with shifted xlabel numbers

Is there a way to adjust the x and y axis label numbers by adding +2? In other words, I have created this image but I need the label numbers to start with 2: https://i.stack.imgur.com/LeHjF.png Here is the code I used: jacaardMatrix = 1.6628873771730914 ...

Exploring Python's Dictionary Manipulation

In Python, I have crafted a dictionary where words from a given text are stored as keys and the number of times they appear in the text is tracked as the corresponding values. This dictionary has been sorted based on the frequency of occurrence in descendi ...

When utilizing a dictionary and the map function to create a new column in a DataFrame, the result is

After obtaining a Pandas Dataframe with the following information: Rank % Renewable Country China 1 19.754910 Japan 3 10.232820 Canada 6 61.945430 Germany 7 17.901530 India 8 14.969080 France 9 17.020280 Italy 11 33.6672 ...

Placing a pseudoelement amidst the track and thumb of a range input type

I'm trying to position a pseudo element with a specific z index that is lower than the thumb of an input type range but higher than its track. This is what I have so far: HTML: <div class="range"> <input type="range" name="" class="progre ...

Using force-directed layout to access and retrieve specific data from external or internal data sources

Just starting out with d3js and currently working on modifying the Force directed layout found at http://bl.ocks.org/mbostock/1153292 I have managed to make it so that when I hover over the node circles, the corresponding source value filenames should app ...

Troubles arise when hovering over the <strong> tag and the <h4> element

While hovering over my h4 tag in the table, everything functions correctly. However, when I hover over the strong tag inside the h4 element, the strong tag inherits the same hover effect as the h4 tag. The structure of each td element within the table is ...

Tips for customizing the background color and image of a toaster

Looking to modify the background color and image based on the else condition (toaster.error) success: function (data) { if (data.message != ""){ toastr.success(data.message); ...

transferring files without a user interface

Looking for a solution to upload a file by clicking on an element: <a class="gray_box" href="#">Choose world folder<span>Select the world folder, we'll do the rest</span></a> The issue arises when the file ...

Creating a bootstrap form field that spans 100% in width:

I am encountering an issue with two column divs in a row, each containing two text fields. When resizing on mobile, the width of the textbox is not expanding to 100% and looks unattractive. Below is my Bootstrap code, but strangely, the width looks fine f ...

Support Vector Machines on a one-dimensional array

Currently digging into the Titanic dataset, I've been experimenting with applying an SVM to various individual features using the code snippet below: quanti_vars = ['Age','Pclass','Fare','Parch'] imp_med = Sim ...

Tips for creating sliding header content alongside the header

Is it possible for the content in the header to scroll up, displaying only the navigation list and hiding the logo when a user scrolls on the website? Currently, while the header background slides up, the content within the header remains in place. I feel ...

Finding the smallest value within the data from the past N days

In my dataset, I have the following information: ID Date X 123_Var 456_Var 789_Var A 16-07-19 3 777 250 810 A 17-07-19 9 637 121 529 A 20-07-19 2 295 272 490 A 21-07-19 3 778 600 ...

I encountered an error when trying to locate an element using its class name and xpath in Selenium with Python. The error message displayed was `ERR_SSL_VERSION_OR_CIPHER_MISMATCH`

I am in need of gathering information from a specific webpage that cannot be referenced openly due to its adult content. In order to proceed further, I must first click the age confirmation button on the page. My sole interest is to retrieve the page' ...

Dynamic text input and selection menu with AJAX (PHP and JavaScript)

As a student who is new to Javascript and PHP, I am trying to create a login page for my website that can verify user input in the database using AJAX. For example, when a user enters their username and password, the system should automatically check if t ...

Is there a way to eliminate the border surrounding every cell in a table?

I'm facing an issue with a table on a page with a gray background. The challenge is to remove the borders of the cells in the table. <table width="510"> <tbody> <tr> <td style="background-color: #fff;" colspan="2" width="510"> ...

Set border-image to have rounded corners

I am attempting to create a circular button with a unique border effect. Here is the code I have implemented so far: body { display: flex; height: 100vh; overflow: hidden; justify-content: center; align-items: center; } button { height: 80px ...

Accessing the facebox feature within a dropdown menu

Looking for assistance in creating a function to open a facebox when an option from a drop down list is selected. Here is what I have so far: <select><option value="www.google.com/" id="xxx"></option></select> In the header sectio ...