简体   繁体   中英

C# Selenium Button in a Span Class XPath (Amazon.com)

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>

Chrome 开发者工具的屏幕截图

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM