2

I want to download an Excel file on the web site, but I think i did something wrong. I have HTML code:

<label class="pager">
<input onclick="excelForm.submit()" type="image" value="Excel" src="/YeniSistem/images/Excel_Document_Icon.png">
</label>

What I want to do this with using Selenium I want to click that input with using C#. I have tried in many ways, like:

driver.FindElement(By.XPath(".//html/body/div/div/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div/div/label[2]/input")).Click();

and:

 driver.FindElements(By.XPath(".//div[@id='contentContainer']/div/table/tbody/tr[2]/td/table/tbody/tr[2]")).Click();

and:

driver.FindElements(By.XPath(".//input[contains(@value , 'Excel')]")).Click();

Also I tried previous codes without . in frond of XPath. Please help me to resolve this.

4
  • What exactly is the issue here? Do you get an error, upon clicking? Commented Feb 1, 2020 at 20:30
  • The issue here is i can not click the XPath location, i get error like OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"xpath","selector":".//html/body/div/div/table/tbody/tr[2]/td/table/tbody/tr[2]/td[2]/div/div/label[2]/input"} (Session info: chrome=79.0.3945.130)' Commented Feb 2, 2020 at 18:03
  • Have you tried XPath: .//label[@class='pager']/input? Commented Feb 3, 2020 at 8:53
  • Yes I tried also not working. There are more then one 'pager' class in HTML. Commented Feb 3, 2020 at 9:12

1 Answer 1

1

From your code, I understand that you are trying to download an excel file instead of XPath you can use the following code:

WebClient client = new WebClient();
client.DownloadFile("link here",@"file_path.xlsx");
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it is that I want to do.

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.