Ссылка на веб-сайт: https://www.worldometers.info/world-pop ... opulation/
На самом деле я хочу получить значения, когда навожу курсор на строку графика и собирать данные за каждый год. Годы - с 1951 по 2024 год, так как это сделать
Я пытаюсь использовать координатор x и y svg rect, использовать класс действий селена и использовать moveToELement(), и он не работает, я не знаю почему
Мой код
package selenium_concepts.SVGElements;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.time.Duration;
import java.util.List;
public class IndianPopulationSVGElementTest {
WebDriver driver;
JavascriptExecutor jse;
@BeforeTest
public void setup() {
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
driver.get("https://www.worldometers.info/world-pop ... opulation/");
}
@Test(description = "India Population Graph data test")
public void svgGraphIndiaPopulation() throws InterruptedException {
jse = ((JavascriptExecutor) driver);
WebElement popGraph = driver.findElement(By.xpath("//*[local-name()='svg']//*[name()='g']"));
jse.executeScript("arguments[0].scrollIntoView(true);", popGraph);
String heading = driver.findElement(By.cssSelector("#maincounter-wrap h1")).getText();
String totalPopulationIndia = driver.findElement(By.cssSelector(".maincounter-number span")).getText();
String indianPopulationBetweenYear = driver.findElement(By.xpath("(//div[@class='chart-header'])[1]")).getText();
Thread.sleep(5000);
System.out.println(" -------------- " + heading + " ----------------- ");
System.out.println("Total Population India: " + totalPopulationIndia);
System.out.println("Between Years: " + indianPopulationBetweenYear);
WebElement rectPop = driver.findElement(By.xpath("((//*[local-name()='svg'])[1]//*[name()='g']//*[name()='rect'])[1]"));
Dimension dimension = rectPop.getSize();
int rectHeight = dimension.getHeight();
int rectWidth = dimension.getWidth();
int X = rectPop.getLocation().getX();
int Y = rectPop.getLocation().getY();
System.out.println("X: " + X);
System.out.println("Y: " + Y);
System.out.println("Dimension: " + dimension);
System.out.println("Height: " + rectHeight);
System.out.println("Width: " + rectWidth);
// height == 260
// y = (260/2) - 260 = -130
int getTopLeftY = ((rectPop.getSize().getHeight()) / 2 - rectPop.getSize().getHeight());
// weight = 520
// X = (520/2) - 520 == -260
int getTopLeftX = ((rectPop.getSize().getWidth()) / 2 - rectPop.getSize().getWidth());
Actions actions = new Actions(driver);
for(int i = 0; i < 50; i++) {
actions.moveToElement(rectPop, getTopLeftX, getTopLeftY).perform();
}
/*
WebElement popGraphSVG = driver.findElement(By.xpath("//*[local-name()='svg']//*[name()='defs' and @id='_ABSTRACT_RENDERER_ID_0']"));
Actions actions = new Actions(driver);
actions.moveToElement(popGraphSVG).perform();
Thread.sleep(4000);
actions.click();
List tooltipsContents = driver.findElements(By.xpath("//*[local-name()='svg']//*[name()='g' and @class='google-visualization-tooltip']//*[name()='g']//*[name()='text']"));
String populationYear = tooltipsContents.getFirst().getText();
String totalPopulationInYear = tooltipsContents.get(2).getText();
System.out.println(populationYear + " ----> " + totalPopulationInYear);
WebElement tracker = driver.findElement(By.xpath("(//*[local-name()='svg']//*[name()='g']//*[name()='circle'])[1]"));
for (int i = 1; i
Подробнее здесь: https://stackoverflow.com/questions/788 ... enium-java
Автоматизируйте график SVG с помощью Selenium Java ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1722441524
Anonymous
Ссылка на веб-сайт: https://www.worldometers.info/world-population/india-population/
На самом деле я хочу получить значения, когда навожу курсор на строку графика и собирать данные за каждый год. Годы - с 1951 по 2024 год, так как это сделать
Я пытаюсь использовать координатор x и y svg rect, использовать класс действий селена и использовать moveToELement(), и он не работает, я не знаю почему
Мой код
package selenium_concepts.SVGElements;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.time.Duration;
import java.util.List;
public class IndianPopulationSVGElementTest {
WebDriver driver;
JavascriptExecutor jse;
@BeforeTest
public void setup() {
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(20));
driver.get("https://www.worldometers.info/world-population/india-population/");
}
@Test(description = "India Population Graph data test")
public void svgGraphIndiaPopulation() throws InterruptedException {
jse = ((JavascriptExecutor) driver);
WebElement popGraph = driver.findElement(By.xpath("//*[local-name()='svg']//*[name()='g']"));
jse.executeScript("arguments[0].scrollIntoView(true);", popGraph);
String heading = driver.findElement(By.cssSelector("#maincounter-wrap h1")).getText();
String totalPopulationIndia = driver.findElement(By.cssSelector(".maincounter-number span")).getText();
String indianPopulationBetweenYear = driver.findElement(By.xpath("(//div[@class='chart-header'])[1]")).getText();
Thread.sleep(5000);
System.out.println(" -------------- " + heading + " ----------------- ");
System.out.println("Total Population India: " + totalPopulationIndia);
System.out.println("Between Years: " + indianPopulationBetweenYear);
WebElement rectPop = driver.findElement(By.xpath("((//*[local-name()='svg'])[1]//*[name()='g']//*[name()='rect'])[1]"));
Dimension dimension = rectPop.getSize();
int rectHeight = dimension.getHeight();
int rectWidth = dimension.getWidth();
int X = rectPop.getLocation().getX();
int Y = rectPop.getLocation().getY();
System.out.println("X: " + X);
System.out.println("Y: " + Y);
System.out.println("Dimension: " + dimension);
System.out.println("Height: " + rectHeight);
System.out.println("Width: " + rectWidth);
// height == 260
// y = (260/2) - 260 = -130
int getTopLeftY = ((rectPop.getSize().getHeight()) / 2 - rectPop.getSize().getHeight());
// weight = 520
// X = (520/2) - 520 == -260
int getTopLeftX = ((rectPop.getSize().getWidth()) / 2 - rectPop.getSize().getWidth());
Actions actions = new Actions(driver);
for(int i = 0; i < 50; i++) {
actions.moveToElement(rectPop, getTopLeftX, getTopLeftY).perform();
}
/*
WebElement popGraphSVG = driver.findElement(By.xpath("//*[local-name()='svg']//*[name()='defs' and @id='_ABSTRACT_RENDERER_ID_0']"));
Actions actions = new Actions(driver);
actions.moveToElement(popGraphSVG).perform();
Thread.sleep(4000);
actions.click();
List tooltipsContents = driver.findElements(By.xpath("//*[local-name()='svg']//*[name()='g' and @class='google-visualization-tooltip']//*[name()='g']//*[name()='text']"));
String populationYear = tooltipsContents.getFirst().getText();
String totalPopulationInYear = tooltipsContents.get(2).getText();
System.out.println(populationYear + " ----> " + totalPopulationInYear);
WebElement tracker = driver.findElement(By.xpath("(//*[local-name()='svg']//*[name()='g']//*[name()='circle'])[1]"));
for (int i = 1; i
Подробнее здесь: [url]https://stackoverflow.com/questions/78813373/automate-svg-graph-using-selenium-java[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия