How to Scroll down a custom Menu in selenium webdriver | Selenium Forum
P
Prithwiraj Posted on 22/06/2022

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import jdk.internal.org.objectweb.asm.tree.analysis.Value;
import sun.font.Script;

public class ROC {
public static void main(String[] args) {
/*
* int a=100; System.out.println(a);
*
*
*/


WebDriver driver1=null;



//System.setProperty("webdriver.gecko.driver", "C:\\geckodriver.exe");
//driver1 =new FirefoxDriver();



System.setProperty("webdriver.chrome.driver", "C:\\Curde\\chromedriver.exe");

driver1 = new ChromeDriver();
driver1.manage().window().maximize();
//driver = new ChromeDriver();

driver1.get("https://alpha.rentoncloud.com/");
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
WebElement usernamefield = driver1.findElement(By.name("email"));
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
usernamefield.sendKeys("jack_cornor@mailinator.com");
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
WebElement submitbutton = driver1.findElement(By.xpath("/html/body/div[1]/div/div/div/div/div/div/div/div[2]/form/div[2]/button"));
//passwordfield.sendKeys("Export123()");
//WebElement submitbutton = driver.findElement(By.name("proceed"));
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
submitbutton.click();


driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
WebElement passwordfield1 = driver1.findElement(By.xpath("/html/body/div[1]/div/div/div/div/div/div/div/div/form/div[2]/input"));
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
passwordfield1.sendKeys("mylogin123");
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

WebElement submitbutton1 = driver1.findElement(By.xpath("/html/body/div[1]/div/div/div/div/div/div/div/div/form/div[4]/button"));
//passwordfield.sendKeys("Export123()");
//WebElement submitbutton = driver.findElement(By.name("proceed"));
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

submitbutton1.click();
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
//driver1.switchTo().alert().sendKeys("you are logged in");

System.out.println("You have logged in successfully");

///html/body/div[1]/div/div[2]/section/main/div[2]/div/div[1]/div/div/button/span
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
//WebElement myaccount = driver1.findElement(By.xpath("//*[@class='container']//*[text()='My account']"));
//passwordfield.sendKeys("Export123()");
//WebElement submitbutton = driver.findElement(By.name("proceed"));

////*[@class='ant-btn ant-btn-primary']//*[text()='My account']
//driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
//System.out.println("before bug");

//myaccount.getClass();

//myaccount.click();

//WebElement My_Account = driver1.findElement(By.xpath("//*[@class='container']//*[text()='My account']"));
//passwordfield.sendKeys("Export123()");
//WebElement submitbutton = driver.findElement(By.name("proceed"));

WebElement My_account=driver1.findElement(By.cssSelector("#root > div > div:nth-child(2) > section > main > div.container > div > div.ant-list-header > div > div > button > span"));
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

My_account.click();

//System.out.println("After bug" );
driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

JavascriptExecutor js=(JavascriptExecutor) driver1;

//WebElement menu1 = driver1.findElement(By.xpath("/html/body/div[1]/div/div[2]/section/div/aside/div"));
//passwordfield.sendKeys("Export123()");
//WebElement submitbutton = driver.findElement(By.name("proceed"));

////*[@class='ant-btn ant-btn-primary']//*[text()='My account']
//driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);

js.executeScript("document.querySelector('.ant-menu.ant-menu-root.ant-menu-inline.ant-menu-light').scrollTop=400") ;

int pageobject=document.querySelector(".ant-menu.ant-menu-root.ant-menu-inline.ant-menu-light");
//WebElement menu1 = driver1.findElement(By.className("ant-layout-sider-children"));
//driver1.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
//menu1.sendKeys(Keys.PAGE_DOWN);

//JavascriptExecutor executor = (JavascriptExecutor) driver1;
//executor.executeScript("arguments[0].scrollIntoView(true)", menu1);

// executor.executeScript("arguments[0].scroll;", menu1);
//IWebElement scroll =driver1.findElement(By.className("ant-layout-sider-children"));

}

}


P
Prithwiraj Replied on 22/06/2022

Its done by google. Mistake to choose xpath


A
Ashish Replied on 12/07/2022

ok