Is it possible to get an instance of the driver inside HtmlBlock in HtmlElements?
I am using frameworks HtmlElements
( https://github.com/yandex-qatools/htmlelements ) for my Java websites. Is it possible to get a webdriver instance inside HtmlBlock
? For example, implement additional logic in some fields, or implement a function to wait for completion ajax
.
source to share
Take a look at this piece of code:
@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
source to share
As I understand you. You need the WebDriver in your page block, not in the page class.
The easy, but not elegant, way is to create a static variable and store the WebDriver instance in it so that you can use the WebDriver anywhere in your code.
Addition I am assuming you are an instance of Page in your test and in the page constructor you are calling
HtmlElementLoader.populatePageObject(this, driver);
But I think you can try to start your block manually.
class Page {
@FindBy(...)
HtmlBlock block;
public Page(){
HtmlElementLoader.populatePageObject(this, driver);
this.block = new HtmlBlock(driver);
}
}
And in the HtmlBlock create a constructor that will save the WebDriver in a local field.
public HtmlBlock(WebDriver driver){
this.driver = driver;
HtmlElementLoader.populatePageObject(this, driver);
}
I'm not sure about the second option, but something like this should work.
source to share