Код:
Код: Выделить всё
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;
public class Main {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\ChromeD\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.infomoney.com.br/mercados/");
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); // Maximum wait time of 30 seconds
wait.until((ExpectedCondition) wd ->
((JavascriptExecutor) wd).executeScript("return document.readyState").equals("complete"));
// Locate the "Load more" button
WebElement loadMoreButton = wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath("//button[contains(@class, 'text-white') and contains(@class, 'bg-wl-neutral-950')]")));
// Scroll to the button using JavaScript
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView(true);", loadMoreButton);
loadMoreButton.click();
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... a-selenium