Problems interacting with Wep pages using Selenium in Java

I am trying to use the HtmlUnitDriver and WebElement classes for Selenium in Java to click the Download as CSV button in Google trends.

The problem is that this button is hidden (not displayed) until you click another button on the settings menu, but I cannot click this button on the settings menu using WebElement.

Here is my code:

/**
 * @args String, the term to search on Google Trends
 */
public static void main(String[] args)
{
    //instantiate an HtmlUnitDriver
    HtmlUnitDriver hud = new HtmlUnitDriver();

    //navigate to the 90-day Google Trends page of the input term in args
    hud.get("https://www.google.com/trends/explore#q=" + args[0] + "&date=today%203-m&cmpt=q&tz=Etc%2FGMT%2B8");

    //set element to the first button to press
    WebElement element = hud.findElement(By.id("settings-menu-button"));

    //click the element
    element.click();
}

The error I get is: org.openqa.selenium.ElementNotVisibleException: you can only interact with visible elements

But is the settings menu button visible?

This is the first time I am making such a program and using this library, so thanks for any help. I am still studying.

+4
2

public static void main(String[] args)
{
    //instantiate an HtmlUnitDriver
    HtmlUnitDriver hud = new HtmlUnitDriver();
    wait = new WebDriverWait(hud , 120);
    //navigate to the 90-day Google Trends page of the input term in args
    hud.get("https://www.google.com/trends/explore#q=" + args[0] + "&date=today%203-m&cmpt=q&tz=Etc%2FGMT%2B8");
       wait.until(ExpectedConditions.presenceOfElementLocated(By.id("settings-menu-button")).click();

   }
0

(, Firefox, Chrome):

ChromeDriver hud = new ChromeDriver();

:

javascript, HtmlUnit (Rhino). javascript, HtmlUnit, .

JavaScript DOM , / , (, CSS ..)

0

Source: https://habr.com/ru/post/1619594/


All Articles