Why is RSelenium unable to find my xpath?

58 Views Asked by At

I have to perform a search repeatedly on a website (https://franklin.genoox.com/clinical-db/home) A long time ago I found the Rselenium package and I have used it successfully in previous times (After wracking my brain a lot, because I'm really new into web scrapping). The elements always were input class with a clear id (easy to find). Today I need to develop a script again that allows me to make automatic searches on this new web. But I am not able to find the correct xpath for the search bar to insert my search.

I attach an image of the search bar where I need to write. Search bar

I've tried a recommended Google Chrome extension called SelectorGadget. Supposedly it locates the xpath correctly. SelectorGadget tells me that the XPath of the search bar is this:

"//*[contains(concat( " ", @class, " " ), concat( " ", "ng-touched", " " ))]"

First, I don't know how to find this xpath by myself. When I try to "inspect" the web page and click to obtain the xpath of the search bar I obtain something really different:

My own way to obtain the xpath of the search bar

The result is: "/html/body/app-root/div/gnx-home-page/div/gnx-search/div2/input"

Can anyone explain me about this difference?

Moreover, when I try to find the Element I get an error message:

query <- remDr$findElement(using = "xpath", value = '//*[contains(concat( " ", @class, " " ), concat( " ", "ng-touched", " " ))]')

The error message is the following:

Selenium message:Unable to locate element: //*[contains(concat( " ", @class, " " ), concat( " ", "ng-touched", " " ))] For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html Build info: version: '4.0.0-alpha-2', revision: 'f148142cf8', time: '2019-07-01T21:30:10' System info: host: 'PORTATIL_MARIA', ip: '192.168.8.102', os.name: 'Windows 11', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_401' Driver info: driver.version: unknown

Error: Summary: NoSuchElement Detail: An element could not be located on the page using the given search parameters. class: org.openqa.selenium.NoSuchElementException Further Details: run errorDetails method

How Can I solve this problem? Why can't I find the correct XPath?

1

There are 1 best solutions below

0
datawookie On

Try these:

  • CSS selector: .search-wrapper > input or
  • XPath: //*[@class='search-wrapper']/input.

Testing in Developer Tools both seem to work.

enter image description here

See this post for a few more details.