Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searching with RelativeLocator does not work #135

Open
keinhaar opened this issue Sep 8, 2023 · 3 comments
Open

Searching with RelativeLocator does not work #135

keinhaar opened this issue Sep 8, 2023 · 3 comments

Comments

@keinhaar
Copy link

keinhaar commented Sep 8, 2023

I'm trying to run my automated tests headless with this driver, but it does not work, because the RelativeLocator seems to have 2 Problems:

  1. It uses an injected Javascript file named findElements.js (in selenium-support-4.12.1.jar) which contains a regex replace a=a.replace(t?/(^|\s|\b)(\S)/g:/(^|[^\d\p{L}\p{S}])([\p{Ll}|\p{S}])/gu in line 111. htmlunit complains about the invalid flag "u" at the end. I removed it, and the error is gone. Don't know what side effects this will have.
  2. After fixing the first, i now get another error (see below). I really don't understand what that means, because it works with the firefox driver, and a simple WebElement el = driver.findElement(By.xpath("//div[text()='Username']"); works as expected. The error occurs if I use RelativeLocator.with(By.tagName("input")).toRightOf(By.xpath("//div[text()='Username']");

Any help would be great.

org.openqa.selenium.WebDriverException: org.htmlunit.ScriptException: InvalidSelectorError: Unable to locate an element with the xpath expression //div[text()='Username'] because of the following error: TypeError: Cannot find function lookupPrefix in object [object HTMLHtmlElement]. (injected script#91) Build info: version: '4.12.1', revision: '8e34639b11' System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.16.1' Driver info: driver.version: HtmlUnitDriver at org.openqa.selenium.htmlunit.HtmlUnitDriver.executeScript(HtmlUnitDriver.java:841) at org.openqa.selenium.support.locators.RelativeLocator$RelativeBy.findElements(RelativeLocator.java:194) at org.openqa.selenium.By.findElement(By.java:122) at org.openqa.selenium.htmlunit.HtmlUnitElementFinder.findElement(HtmlUnitElementFinder.java:68) at org.openqa.selenium.htmlunit.HtmlUnitDriver.lambda$findElement$8(HtmlUnitDriver.java:713) at org.openqa.selenium.htmlunit.HtmlUnitDriver.implicitlyWaitFor(HtmlUnitDriver.java:1172) at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElement(HtmlUnitDriver.java:713) Caused by: org.htmlunit.ScriptException: InvalidSelectorError: Unable to locate an element with the xpath expression //div[text()='Username'] because of the following error: TypeError: Cannot find function lookupPrefix in object [object HTMLHtmlElement]. (injected script#91) at org.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:996) at org.htmlunit.corejs.javascript.Context.call(Context.java:590) at org.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:484) at org.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:348) at org.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:923)

@rbri
Copy link
Collaborator

rbri commented Sep 8, 2023

@keinhaar looks like you are reaching some of the not yet implemented corners of the js support.
The first one (flag "u") is a problem of Rhino itself, but we are already working on this. Maybe there is hope to have it at the end of the year.

The second more or less says that HtmlUnit DomNodes are not supporting the method lookupPrefix() right now - or that you are the first one using this methods ;-)

Usually it is possible to add support for such methods. It will help if you can provide your findElements.js or even more details about your solution to give me the chance to write a unit test.

And the bad news at the end... i will be out for the next two weeks - to you need this soon or is it ok to wait a bit?

@keinhaar
Copy link
Author

keinhaar commented Sep 8, 2023

Thanks for the fast response.
The findElements.js is contained in selenium distribution in the jar selenium-support.jar or on github:
https://github.com/SeleniumHQ/selenium/tree/d1a59128b785ffa5d76a4a11b4663250f52197a1/rb/lib/selenium/webdriver/atoms
There is nothing special in my tests, because i'm just beginning to automate. The lookupPrefix() method is called from the findElements.js script, which is injected by selenium when using seleniums RelativeLocator.

I understand that i can't expect a quick fix. I'm totally fine to wait a bit ;-)

@rbri
Copy link
Collaborator

rbri commented Sep 8, 2023

Ok, looks like i have sufficient info for making a local test case - will inform you about the progress.

Thanks a lot for reporting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants