diff --git a/README.adoc b/README.adoc index 7f165a4..a337a96 100644 --- a/README.adoc +++ b/README.adoc @@ -14,8 +14,28 @@ headless=false download.dir= -* Usage: +== Usage +=== Init - var confPath = Path.of("/foo/tabdriver.properties"); - var td = TabDriverBuilder.build(confPath); \ No newline at end of file +[source,java] +var confPath = Path.of("/foo/tabdriver.properties"); +var td = TabDriverBuilder.build(confPath); + +=== Web Navigation + +* `TabDriver` is somewhat opionionated. +* The default way of fetching an element is by `css` selector. +** i.e. `td.findByCss("input[name='q']")` +** this returns an `Optional` which the consumer can +** the optional is empty on any error. +decide how to consume. + +=== Quick Recap of CSS Selectors + +|=== +| Selector | Description +| `[class*='x']` , `[aria-label*='x']` | `attribute` containing `x` +| button[class*='email'] | button with a class containing the word `email` +| form[action*='sign'] | form with an action attribute containing the word `sign` +| button.tv-button#email-signin | button with class `tv-button` and id `email-signin` diff --git a/src/main/java/com/olexyn/tabdriver/TabDriver.java b/src/main/java/com/olexyn/tabdriver/TabDriver.java index 9858ff2..03e8fed 100644 --- a/src/main/java/com/olexyn/tabdriver/TabDriver.java +++ b/src/main/java/com/olexyn/tabdriver/TabDriver.java @@ -1,7 +1,6 @@ package com.olexyn.tabdriver; import com.olexyn.min.log.LogU; -import org.checkerframework.checker.nullness.qual.Nullable; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Keys; @@ -318,6 +317,14 @@ public class TabDriver implements JavascriptExecutor { } } + public synchronized Optional findByCss(WebElement context, String css) { + try { + return Optional.of(context.findElement(By.cssSelector(css))); + } catch (Exception e) { + return Optional.empty(); + } + } + /** * Any-Match. */