Issue
I am automating downloading files and in order to find these files I need to select a date from one dropdown menu called 'Select Period' and the other value I need to select is 'All Types' from the dropdown menu called 'Select File Type'. The html code does not have a select tag but I can use Class Name. I am able to do this. The problem comes in when I need to select a button called 'Start Report'. The nature of the button is as such that once you select a value from both dropdowns, then only will this button become available to be selected.
I have tried this code here:
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()
It does not work, here is some extra info about the html code: enter image description here enter image description hereenter image description here
Solution
You didn't provide many details about that 'Start Report' button but, in general, the <p> tag is not usually used for the buttons.
Try to look above the <p> tag, maybe there is some <button> or <a> tag that represents your button.
Also, sticking to the class names in locators is not always a good idea, because they tend to change often.
If your 'Start Report' button appears somewhere outside of the visible area, you can use ActionChains to move to the target element. Try the following code, but first, check 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)
# navigate to the page
driver.get("your_page_url")
# select period
select_from_dropdown(wait, "your_select_period_dropdown_xpath", "your_select_period_dropdown_value_xpath")
# select file type
select_from_dropdown(wait, "your_select_type_dropdown_xpath", "your_select_type_dropdown_value_xpath")
# wait for the button to be visible
start_report_btn = wait.until(EC.visibility_of_element_located((By.XPATH, "//p[text()='Start Report']")))
# move to the button and do a click
actions.move_to_element(start_report_btn).click(start_report_btn).perform()
Answered By - sashkins
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.