1

I am trying to get absolute XPath of an element but in Google I can find results only to get element from XPath.

IWebElement webElement = (IWebElement)((IJavaScriptExecutor)webDriver).ExecuteScript("return document.elementFromPoint(arguments[0], arguments[1])", windowPoint.x, windowPoint.y);

I can see some of the answers Want to Retrieve Xpath of Given WebElement for Java.

Can we get XPath details of an element using C# code?

Tech Learner
  • 1,227
  • 6
  • 24
  • 59
  • What do you mean? _I am trying to get absolute XPath of an element_ - You can not do that programmatically, obviously there's no need as well. – cruisepandey Dec 23 '21 at 12:08
  • @cruisepandey - In my question, I've given link with Java example. I need similar solution for C#.Net. – Tech Learner Dec 23 '21 at 12:10
  • 1
    You can use the one from the java example. Just modify it to c#. public static string GetAbsoluteXPath(IWebElement element) { return (string)((IJavaScriptExecutor)driver).ExecuteScript( /// extra code ); – art_architect Dec 23 '21 at 20:41
  • I think the bigger question is *why* you need the absolute xpath. That is the problem you need to solve. – Greg Burghardt Feb 04 '22 at 16:16
  • @GregBurghardt - I need absolute XPath details for automation purpose. – Tech Learner Feb 05 '22 at 03:18
  • @GregBurghardt - Can you please share the link here if the answer is already available. – Tech Learner Feb 05 '22 at 06:11
  • I don't have the answer because you haven't asked the question. Can you tell us why you need the absolute xpath? There might be a better solution to your problem. – Greg Burghardt Feb 05 '22 at 12:59
  • IWebElement webElement => Driver.FindElement(By.XPath("//li/a"]")); is how we define th e XPath in selenium with C# if you say yes I can provide you with a complete answer. – joekevinrayan96 May 07 '22 at 04:35

0 Answers0