我正在尝试在XPATH
中创建正确的C#
语法,以点击亚马逊商业网站上的下载按钮。我尝试的一切都无法找到按钮。以下是我尝试过的一些事情:
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();
以下是亚马逊网页的源代码。谁能帮我设计合适的XPATH查询来点击这个下载按钮?谢谢。
<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>
答案 0 :(得分:1)
您应该尝试使用WebElement#click()
来执行点击元素,如下所示: -
driver.FindElement(By.CssSelector("input.a-button-input[aria-labelledby = 'downloadCSV_button-announce']")).Click();
或者如果span
元素可点击,请尝试: -
driver.FindElement(By.Id("downloadCSV_button-announce")).Click();
或者
driver.FindElement(By.Id("downloadCSV_button")).Click();