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

IllegalArgumentException: To search for element by tag, use By.tag() instead of tag as CSS selector. #303

Closed
javydreamercsw opened this issue Jul 31, 2019 · 18 comments · Fixed by #388
Labels
bug Something isn't working

Comments

@javydreamercsw
Copy link

javydreamercsw commented Jul 31, 2019

Looks like this needs to be updated to use By.tag() instead.

at de.retest.web.selenium.TestHealer.retrieveUsableCssSelector(TestHealer.java:161)
	at de.retest.web.selenium.TestHealer.findElementByCssSelector(TestHealer.java:139)
	at de.retest.web.selenium.TestHealer.findElement(TestHealer.java:66)
	at de.retest.web.selenium.TestHealer.findElement(TestHealer.java:49)
	at de.retest.web.selenium.UnbreakableDriver.findElement(UnbreakableDriver.java:81)
	at de.retest.web.selenium.AutocheckingRecheckDriver.findElement(AutocheckingRecheckDriver.java:107)
	at jdk.internal.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.openqa.selenium.support.events.EventFiringWebDriver.lambda$new$1(EventFiringWebDriver.java:105)
	at com.sun.proxy.$Proxy17.findElement(Unknown Source)
	at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:194)
@javydreamercsw
Copy link
Author

This failure only happened for me on Mac 10.14 Safari, Windows 10 Firefox

@roesslerj
Copy link
Contributor

Thanks for raising this issue. I addressed it in #304. However, it will only work for simple CSS selectors, not for complex ones...

@diba1013 diba1013 added the bug Something isn't working label Aug 1, 2019
@javydreamercsw
Copy link
Author

Did this made it into 1.5.0 or 1.5.1? Still seeing this issue on 1.5.1.

@diba1013
Copy link

We proposed a fix with the PR mentioned above. If this does not fix your problem, I kindly ask you to describe your setup.

Apparently you are trying to find an element by a css selector. However, we currently support only basic selectors, starting with # or . (e.g. #foo, .bar) and not contain additional selectors. If this is not the case, we throw above exception.

For now, I would suggest that you convert your css selector into a xpath selector or use a different By if possible.

@roesslerj
Copy link
Contributor

Or could you just give the complete findElement expression that triggers that error?

@roesslerj
Copy link
Contributor

... to properly answer your question: The fix (#304) made it into the release. Therefore if it still occurs, we need to refine that by better understanding your concrete problem.

@javydreamercsw
Copy link
Author

This only occurs when using the AutocheckingRecheckDriver. Basically this is the code at fault:

@Override
  public Object scrollIntoView(WebElement element) {
    try {
      return ((JavascriptExecutor) getWebDriver())
          .executeScript("arguments[0].scrollIntoView(true);", element);
    } catch (Exception ex) {
      LOG.debug("Unable to scroll into view: " + element, ex);
    }
    return null;
  }

The return line leads to the following stack trace:

java.lang.IllegalArgumentException: To search for element by tag, use `By.tagName()` instead of `tag` as CSS selector.
	at de.retest.web.selenium.TestHealer.retrieveUsableCssSelector(TestHealer.java:177)
	at de.retest.web.selenium.TestHealer.findElementByCssSelector(TestHealer.java:155)
	at de.retest.web.selenium.TestHealer.findElement(TestHealer.java:75)
	at de.retest.web.selenium.TestHealer.findElement(TestHealer.java:51)
	at de.retest.web.selenium.UnbreakableDriver.findElement(UnbreakableDriver.java:84)
	at de.retest.web.selenium.AutocheckingRecheckDriver.findElement(AutocheckingRecheckDriver.java:136)
	at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.openqa.selenium.support.events.EventFiringWebDriver.lambda$new$1(EventFiringWebDriver.java:105)
	at com.sun.proxy.$Proxy31.findElement(Unknown Source)
	at org.openqa.selenium.support.events.EventFiringWebDriver.findElement(EventFiringWebDriver.java:194)
	at com.github.webdriverextensions.internal.WebDriverExtensionElementLocator.findElement(WebDriverExtensionElementLocator.java:37)
	at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:38)
	at com.sun.proxy.$Proxy34.toString(Unknown Source)
	at java.base/java.lang.String.valueOf(String.java:2951)
	at java.base/java.lang.StringBuilder.append(StringBuilder.java:168)

@roesslerj
Copy link
Contributor

Hey, thanks for providing more input. Sorry for still not understanding ... where is that scrollIntoView method from? Is this recheck code? And how and when is it called for leading to that stack trace?

@javydreamercsw
Copy link
Author

javydreamercsw commented Oct 23, 2019

This is part of my platform code. Seems that using a WebElement using Selenium exclusive methods in something like this:

private WebElement waitForClickable(int seconds, WebElement webElement) {
    WebDriverWait wait = new WebDriverWait(getWebDriver(), seconds);
    return wait.until(ExpectedConditions.elementToBeClickable(webElement));
  }

Triggers the error when AutocheckingRecheckDriver takes over. The WebElements are triggering the stack trace above defined like this:

@FindBy(css = "[data-id=\"id\"]")

@javydreamercsw
Copy link
Author

FYI this showed up during the monitoring phase of the tests implemented using the tool and it's currently blocking any progress towards a decision in using the tool as part of our tests.

@diba1013
Copy link

We are working on a workaround in 1.6.0, so that no exception will be thrown and your test will continue. We will try—however, I cannot promise—to have a solution for the next release that makes your element unbreakable. So to say, the exception should not be thrown with the next release.

In the meantime you may use another By like By.id that is currently supported, if your element allows so.

@javydreamercsw
Copy link
Author

javydreamercsw commented Oct 25, 2019 via email

@roesslerj
Copy link
Contributor

As mentioned, we fixed the exception being thrown. Supporting more complex CSS attributes will be tracked in #389 and #390.

@diba1013
Copy link

diba1013 commented Nov 4, 2019

We partially implemented this in recheck-web-1.6.0 for which we have a new release available. If you find any issues regarding this problem, please reopen this ticket and post the exception and/or log here.

Please us the following versions:

Edit: Updated to most up to date releases.

@roesslerj
Copy link
Contributor

By "partially implemented", diba1013 meant that it should work for you case specifically, and for most cases that use CSS selectors ... but not for each edge-case of possible CSS selectors... Please report any remaining problems on that. Thanks

@javydreamercsw
Copy link
Author

Haven't had a chance to try it. Was not a drop in replacement as some classes were missing. Is there a recheck-web beta with this changes?

@diba1013
Copy link

diba1013 commented Nov 7, 2019

We released a full release 1.6.0 already which should be on maven central by now. However, it is still not visible in maven repository. Sadly, we have no influence on when the artifact is available, as we have no open release in sonatype.

Could you describe what classes are missing? If those are essential classes (like RecheckImpl or RecheckOptions) this is most likely that the dependency could not be resolved (i.e. missing). Could you check in your respective library view in eclipse or IntelliJ?

@javydreamercsw
Copy link
Author

This morning seems it was resolving fine. Still need to do some more tests but at least seems to be resolve now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

3 participants