Lorem Ipsum只是印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是业界标准的虚拟文本,当时一台未知的打印机采用了类型的厨房,并将其打碎以制作样本书。
包PackageQandle;
//import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
//import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
//import junit.framework.Assert;
public class Adduser {
public static void main(String[] args) throws Throwable {
System.setProperty("webdriver.gecko.driver","C:/Users/sudhir/geckodriver-v0.18.0-win32/geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver();
driver.get("https://prod4.qandle.com");
WebDriverWait webwait = new WebDriverWait(driver,120);
webwait.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath(".//*[@id='login-email']")));
WebElement web = driver.findElementByXPath(".//*[@id='login-email']");
web.sendKeys("Anil@gmail.com");
WebDriverWait webwait1 = new WebDriverWait(driver,20);
webwait1.until(ExpectedConditions.elementToBeClickable(driver.findElementByXPath(".//*[@id='login-password']")));
WebElement web1 = driver.findElementByXPath(".//*[@id='login-password']");
web1.sendKeys("Abc12345");
WebElement web2 = driver.findElementByXPath(".//*[@id='signInSubmit']");
web2.submit();
//Assert.assertEquals(my_Title, my_ExpectedTitle);
Thread.sleep(5000);
//JavascriptExecutor j = new JavascriptExecutor();
String my_Title = driver.getCurrentUrl();
//System.out.println(my_Title);
String my_ExpectedTitle = "https://prod4.qandle.com/#/";
if(my_Title.equals(my_ExpectedTitle)){
driver.executeScript("Scroll(0,600);");
}else{
System.out.println("Test Case Failed");
}
}
}
I am using this code to inspect element which appears when i scroll down
the page.So help me in this and provide me solution.I have tried it with so many solutions.
答案 0 :(得分:0)
Lorem Ipsum只是印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是业界标准的虚拟文本,当时一台未知的打印机采用了类型的厨房,并将其打碎以制作样本书。
答案 1 :(得分:0)
findElementByXpath的语法必须是
driver.findElement(By.xpath( “.//*[@ ID = '登录密码']”));
尝试下面提到的代码滚动到元素,它对我有用
driver.get("https://prod4.qandle.com");
WebDriverWait webwait = new WebDriverWait(driver,120);
webwait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath(".//*[@id='login-email']"))));
WebElement web = driver.findElement(By.xpath(".//*[@id='login-email']"));
web.sendKeys("Anil@gmail.com");
WebDriverWait webwait1 = new WebDriverWait(driver,20);
webwait1.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath(".//*[@id='login-password']"))));
WebElement web1 = driver.findElement(By.xpath(".//*[@id='login-password']"));
web1.sendKeys("Abc12345");
WebElement web2 = driver.findElement(By.xpath(".//*[@id='signInSubmit']"));
web2.submit();
//Assert.assertEquals(my_Title, my_ExpectedTitle);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String my_Title = driver.getCurrentUrl();
String my_ExpectedTitle = "https://prod4.qandle.com/#/";
if(my_Title.equals(my_ExpectedTitle)){
JavascriptExecutor js = (JavascriptExecutor) driver;
// Mention the xpath of the element to be scrolled for
WebElement tempElement=driver.findElement(By.xpath("//*[contains(text(),'Reports')]"));
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", tempElement);
}else{
System.out.println("Test Case Failed");
}
答案 2 :(得分:0)
如果您使用“Chrome”,请使用:
js.ExecuteScript("arguments[0].scrollIntoViewIfNeeded(true);", e)
对于“Firefox”和“IE”使用:
js.ExecuteScript("arguments[0].scrollIntoView(true);" +
"window.scrollBy(0,-100);", e);