Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't really do this, unfortunately. While Java does support regexpes very well, the WebDriver API does not. Every <code>String</code> parameter in the WebDriver API is taken literally, as a character string, <em>not</em> as a regexp.</p> <p>You have probably confirmed this by running your code. And you have not missed anything, you can't use regexpes in searching for WebElements. If you're wondering why, the reason is that WebDriver has been primarily designed for test automation - you have a front-end test and you don't want to click everything in? Use WebDriver! Are you doing something else? Not sure if you got the right tool for it.</p> <p>Reconsider your approach - <em>why</em> are you trying to match by a regexp? Are you running a website test? Are you not sure what should display there? Well, that's wrong! You should be testing whether you site is behaving like expected.</p> <p>If you're testing after every page load whether the page contains some error message and you are sure you want to do this, consider a different approach. Can you look for a container with <code>id="error-message"</code> or something? Can you look at the URL or a page title whether it contains <code>404 not found</code> or anything similar you need to assert?</p> <p>What you can do?</p> <ul> <li>Try not to search by text if you don't have to.</li> <li>Dive into <a href="http://www.w3.org/TR/xpath/" rel="nofollow noreferrer">XPath 1.0</a> and see what it can do for you. While there are no regexp-enabling functions (<a href="http://www.w3.org/TR/xquery-operators/#func-matches" rel="nofollow noreferrer">those could be found in XPath 2.0</a>, but we can't use that), there's a lot of strength in there. For example, there's no native <code>lower-case()</code> function, you can use <a href="https://stackoverflow.com/questions/1965529/xpath-how-do-you-do-a-lowercase-call-in-xpath"><code>translate()</code></a>. Or simply use multiple <code>contains()</code> calls. And <a href="http://www.w3.org/TR/xpath/#node-sets" rel="nofollow noreferrer">you can use <code>|</code> to union node-sets</a> together. With these two, you could reconstruct your query with a looooooong XPath. But this is one of the last things you should do. It's bad. Very bad.</li> <li><p>If you're still not convinced you shouldn't search for what you're searching, here's probably the easiest way. I'd still consider it bad since you don't know from where is the Error/Warning/Notice coming, some user might have "Warning: Bad user" as his username. But it does your thing.</p> <pre><code>String bodyText = driver.findElement(By.tagName("body")).getText(); boolean containsError = bodyText.matches("[Ee]rror:|[Ww]arning:|[Nn]otice:|[Ee]xception:"); </code></pre></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload