Čamo
Čamo

Reputation: 4160

Phantomjs browser element.getText() is empty

I have a simple test which prints element.getText() value to console. If I run the code with ChromeDriver it works without any problem. Element is visible also I am waiting till element is visible and also I test the element.isDisplayed() before the getText() call. But if I run it with Phantomjs driver the result of getText() is an empty string. Here is the code:

public void test() throws InterruptedException {
    openPage();

    WebElement header = driver.findElement(By.id("header"));

    new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOf(header));

    System.out.println(header.isDisplayed());
    System.out.println(header.getText());
}

There is a CSS transform on this element.

This is the web page https://tatrytec.eu/, and it is the main header Tatrytec.eu

Can anybody tell me please where could be the problem?

Upvotes: 0

Views: 88

Answers (1)

PDHide
PDHide

Reputation: 19939

https://phantomjs.org/ , this project is suspended as of now. chrome and phantom uses different rendering enginees so it doesn't make sense to use phantomjs now, use chrome headless instead

https://www.chromium.org/blink

Previously headless browsers like phantomjs used to use webkit rendering engine but now chrome has inbuild headless support and uses same rendering enginee blink

https://developers.google.com/web/updates/2017/04/headless-chrome#:~:text=Headless%20Chrome%20is%20similar%20to,the%20latest%20version%20of%20Blink.

Also note w3c is on by default for non headless chrome but for headless chrome it is false and use JSONwire protocol , that doesn't affect quality of test but just for your information

https://stackoverflow.com/a/65841695/6793637

As of Feb , 2021

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1925

Headless chrome doesn't support preferrences setting

you can use headless chroem as :

   ChromeOptions options = new ChromeOptions();
    options.addArguments("headless");
    options.addArguments("window-size=1400,800");       
    options.addArguments("disable-gpu")
    //options.addArguments("--headless", "--disable-gpu", "--window-size=1400,800","--ignore-certificate-errors");
    WebDriver driver = new ChromeDriver(options); 

Upvotes: 1

Related Questions