Is it possible to get instance of driver inside HtmlBlock in HtmlElements?
Take a look at this code snippet:
@Name("Search form")@FindBy(xpath = "//form[@class='f1']")public class SearchArrow extends Test1 { public WebDriver driver;}public class SearchPage { @FindBy(xpath = "//form[@class='f1']") private SearchArrow searchArrow; public SearchPage(WebDriver driver) { HtmlElementLoader.populatePageObject(this, driver); searchArrow.driver = driver; }}
Originally: https://gist.github.com/artkoshelev/4751a4f1b34211e43f4e
As I understand you. You need WebDriver in you page block class, not in Page class.
Simple way, but not elegant, is create a static variable and save WebDriver instance in it, to get the ability use WebDriver in any placein your code.
Addition I guess you instance Pages in your test and in page constructor you call
HtmlElementLoader.populatePageObject(this, driver);
But I think you may try to init your block manualy.
class Page { @FindBy(...) HtmlBlock block; public Page(){ HtmlElementLoader.populatePageObject(this, driver); this.block = new HtmlBlock(driver); }}
And in HtmlBlock create constructor that save WebDriver to local field.
public HtmlBlock(WebDriver driver){ this.driver = driver; HtmlElementLoader.populatePageObject(this, driver);}
I am not sure in second variant, but something like this should work.