1

I am trying to create a proper XPATH syntax in C# to click on a download button from the Amazon business website. Everything I have tried is unable to find the button. Here are some of the things I've tried:

driver.FindElement(By.XPath("//button[@type='submit']")).Submit();

driver.FindElement(By.XPath("//span[contains(@class,'a-button-inner')][contains(text(),'downloadCSV_button-announce')]")).Submit(); 

driver.FindElement(By.XPath("//span[contains(@class,'a-button-inner')][contains(text(),'Download CSV')]")).Submit();

Below is the source code from the Amazon page. Can anyone help me to design the proper XPATH query to click this download button? Thank you.

<h1>Amazon Business Analytics</h1>
<div class="a-row a-spacing-medium a-grid-vertical-align a-grid-center">
    <div class="a-column a-span12">
        <span class="a-declarative" data-action="aba:download-csv" data-aba:download-csv="{}">
            <span id="downloadCSV_button" class="a-button aok-float-right"><span class="a-button-inner"><input class="a-button-input" type="submit" aria-labelledby="downloadCSV_button-announce"><span id="downloadCSV_button-announce" class="a-button-text" aria-hidden="true">Download CSV</span></span></span>
        </span>

Screen shot of Chrome Developer tools

1 Answer 1

1

You should try using WebElement#click() to perform click on element instead as below :-

driver.FindElement(By.CssSelector("input.a-button-input[aria-labelledby = 'downloadCSV_button-announce']")).Click();

Or if span element is clickable try as :-

driver.FindElement(By.Id("downloadCSV_button-announce")).Click();

Or

driver.FindElement(By.Id("downloadCSV_button")).Click();
Sign up to request clarification or add additional context in comments.

4 Comments

Your first answer with the CssSelector worked perfectly. Thanks for your help.
Can I ask you a follow up to your answer? If I wanted to use a wild card when looking for this same tag how could I accomplish that? Like say instead of looking for 'downloadCSV_button-announce', I instead looked for 'download*' where * does not care what else is on the end. How would I do that? Thanks for your help!
Could ask another question regarding this, I or someone will give you answer there, thanks..

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.