selenium拖动滚动条

package com.selenium.gen;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.By;

import org.openqa.selenium.JavascriptExecutor;

import org.testng.Assert;

public class Scroll {

public static void main(String[] args) {

// TODO Auto-generated method stub

//打开浏览器

WebDriver driver=new FirefoxDriver();

//打开网页

driver.get("http://nanjing.xiaomishu.com/shop/search/sp2048_745");

//拖动滚动条

String setscroll = "document.documentElement.scrollTop=" + 500;

((JavascriptExecutor)driver).executeScript(setscroll);

//点击网络建议

driver.findElement(By.xpath(".//*[@id='resFloatBox']/a[1]/u")).click();

//输入姓名

driver.findElement(By.id("repName")).sendKeys("1");

//输入邮件

driver.findElement(By.id("repMail")).sendKeys("1");

//留言

driver.findElement(By.id("repContent")).sendKeys("1");

//点击发送

driver.findElement(By.id("repBtn")).click();

try {

Thread.sleep(5000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Assert.assertEquals("您输入的邮箱格式不正确", driver.findElement(By.xpath("//div[@id='floatBox_remind']/span")).getText());

//关闭浏览器

driver.quit();

}

}

你可能感兴趣的:(selenium拖动滚动条)