1

I am trying to click a button to initiate a file download. The button has hover-over functionality from what I have seen. I have tried clicking via all find_element_by paths.

HTML chunk of the page,

<button class="btn-retrieve ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="sub_1:listPgFrm:j_idt6461:downloadBtn" name="sub_1:listPgFrm:j_idt6461:downloadBtn" onclick="new ice.ace.DataExporter('sub_1:listPgFrm:j_idt6461:downloadBtn', function() { ice.ace.ab(ice.ace.extendAjaxArgs({&quot;source&quot;:&quot;sub_1:listPgFrm:j_idt6461:downloadBtn&quot;,&quot;execute&quot;:'@all',&quot;render&quot;:'@all',&quot;event&quot;:&quot;activate&quot;,&quot;onstart&quot;:function(cfg){showProcessingMessage('Downloading'); return true;;}}, {node:this})); });return false;" style="margin-top: -4px;" role="button" aria-disabled="false"><span class="ui-button-text"><span>Download</span></span></button>

The button's class before hovering is,

"btn-retrieve ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"

The button's class when hovering is,

"btn-retrieve ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-hover"

Selecting the button via the developer window and copying over paths from

<span>Download</span>==$0 

I get the following,

CSS path,

#sub_1\:listPgFrm\:j_idt6461\:downloadBtn > span > span

XPath,

//*[@id="sub_1:listPgFrm:j_idt6461:downloadBtn"]/span/span

Code I have tried,

dwnd = driver.find_element_by_xpath("//*[@id='sub_1:listPgFrm:j_idt6461:downloadBtn']/span")
dwnd.click()

And,

button = driver.find_element_by_css_selector("#sub_1\:listPgFrm\:j_idt6461\:downloadBtn")
download = driver.find_element_by_link_text("Download")
hover = ActionChains(driver).move_to_element(button).move_to_element(download)
hover.click().build().perform()
3
  • 1
    Can you provide the website url? Commented Jan 24, 2022 at 15:14
  • 1
    Can you at least share the page HTML? Not a single element but the whole page? Commented Jan 24, 2022 at 15:22
  • I see. I'm not sure I can do something with that. maybe someone else will be able Commented Jan 24, 2022 at 16:10

1 Answer 1

1

You can use the text-based locator:

//button[.='Download']

Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.

and you can click on it:

Code trial 1:

time.sleep(5)
driver.find_element(By.XPATH, "//button[.='Download']").click()

Code trial 2:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[.='Download']"))).click()

Code trial 3:

time.sleep(5)
button = driver.find_element(By.XPATH, "//button[.='Download']")
driver.execute_script("arguments[0].click();", button)

Code trial 4:

time.sleep(5)
button = driver.find_element(By.XPATH, "//button[.='Download']")
ActionChains(driver).move_to_element(button).click().perform()

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.