Following is the code which I used:
package Test_case;
import java.util.Iterator;
import java.util.Set;
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.interactions.Actions;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
import WIndow_Handle.Handle;
import com.gargoylesoftware.htmlunit.javascript.host.Window;
import Browser.BrowserFactory;
import Excel_Handle.Xls_Reader;
public class Pop_up {
WebDriver driver;
@Test
public void po() throws InterruptedException
{
driver = BrowserFactory.StartBrowser("CHROME", "http://www.hotwheelscollectors.com/2016-red-line-club-membership-classic-hwrlcclub16cl?
catalogId=11551&storeId=10153&langId=-1&krypto=Lg%2FsxAvAfFEmONeOPPSBhUN838Vh4Ifzev0Jt
G1kKfAzF%2F1PbUkSlLdizXE1xJplsYyMZCgU41px%0AUCQz7x2bkcteLnmmzRKYMW5ZSVZf5N%2Fz9wn
rBNk1q19rWdvxP2AJbokWjggbWnMILPDQ2XiImCGH%0AIALv96ukqu7dvQJhC9fo3remzR1pzytUn9kzqeZ
9zfJoiMhpc4vJDTXqn%2Bsy1sh6sB9fQsKI15Cx%0ARUx64TihIhinf1eX%2FkJl08%2BdFNhCaUIcM%2BS5
9NzVAEv08rZXf%2FhjVpmWV43O6xd%2FraA881fc%2Ftfz%0A6pHIEQoJeTiSIlIKn06R83pZWB%2FIVX8
oE8hLLN1k79pGD%2BxV7%2FsFQTX8pGjQ0BFUx6gYk32IoeeK%0Ao3m04CPpfRiy4zBJ99mvjMnW3Xct8
BfAklJXYgg2ssXzRyPIZZfIu7m1miacEeFbJIaCBw6PMsx7%0A2brQjG94fciFFD3p4ZYqJSLOjvpZGKMAwqe
QmOBFVCTkOsOPLhD5DBdfcEIJNb%2F%2Ftcos0kqYiQBG%0A2Khh3JNc8C1aU3FwFzsKJUBVmuDdleTYs
7rpJdJ1YC5LKMuMX8tD8ycwvNekDed3zcmBAZnz%2F56N%0A5UvO%2BazJ3sfuCPc7vf2x9bER97K7hXy
%2B");
WebDriverWait wait = new WebDriverWait(driver, 40);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='WC_QuickInfo_Link_addtocart']")));
driver.findElement(By.xpath("//*[@id='WC_QuickInfo_Link_addtocart']")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='logEmail']")));
//Xls_Reader database1 = new Xls_Reader("D:\\Data.xlsx");
//String usernam= database1.getCellData("HWC", 1, 3);
driver.findElement(By.xpath("//input[@id='logEmail']")).sendKeys("tester3987");
//String Password =database1.getCellData("HWC", 2, 3);
driver.findElement(By.xpath("//input[@id='logPassword']")).sendKeys("Testing01");
driver.findElement(By.xpath("//*[@id='signIn']")).click();
Thread.sleep(1000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='termsA']/div/div[1]/div/div[1]/div[2]/h2[1]")));
WebElement element = driver.findElement(By.xpath("//*[@id='termsA']/div/div[1]/div/div[2]"));
Coordinates cor =((Locatable)element).getCoordinates();
cor.inViewPort();
}
}
Yes I even tried that..but nothing works out. Please help on it.as it's kind of urgent
It's scrolling with my code. But thing is that it's not scrolling to the bottom of pop up ..and I tried action also. Can you please try this.
Actually I am also able to scroll. But not till bottom. And without scrolling, I agree button won't work. There should be a way right. Or its not possible to automate?
yeah try scroll with actions class it might work it uses different mechanism for scroll then java script executor.
I have tried it's not scrolling till the bottom. Please check its. It's kind of urgent.
here try like this
[code:2y89utqk]
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class Pop_up {
WebDriver driver;
@Test
public void po() throws InterruptedException, AWTException {
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.hotwheelscollectors.com/2016-red-line-club-membership-classic-hwrlcclub16cl?catalogId=11551&storeId=10153&langId=-1&krypto=Lg%2FsxAvAfFEmONeOPPSBhUN838Vh4Ifzev0JtG1kKfAzF%2F1PbUkSlLdizXE1xJplsYyMZCgU41px%0AUCQz7x2bkcteLnmmzRKYMW5ZSVZf5N%2Fz9wnrBNk1q19rWdvxP2AJbokWjggbWnMILPDQ2XiImCGH%0AIALv96ukqu7dvQJhC9fo3remzR1pzytUn9kzqeZ9zfJoiMhpc4vJDTXqn%2Bsy1sh6sB9fQsKI15Cx%0ARUx64TihIhinf1eX%2FkJl08%2BdFNhCaUIcM%2BS59NzVAEv08rZXf%2FhjVpmWV43O6xd%2FraA881fc%2Ftfz%0A6pHIEQoJeTiSIlIKn06R83pZWB%2FIVX8oE8hLLN1k79pGD%2BxV7%2FsFQTX8pGjQ0BFUx6gYk32IoeeK%0Ao3m04CPpfRiy4zBJ99mvjMnW3Xct8BfAklJXYgg2ssXzRyPIZZfIu7m1miacEeFbJIaCBw6PMsx7%0A2brQjG94fciFFD3p4ZYqJSLOjvpZGKMAwqeQmOBFVCTkOsOPLhD5DBdfcEIJNb%2F%2Ftcos0kqYiQBG%0A2Khh3JNc8C1aU3FwFzsKJUBVmuDdleTYs7rpJdJ1YC5LKMuMX8tD8ycwvNekDed3zcmBAZnz%2F56N%0A5UvO%2BazJ3sfuCPc7vf2x9bER97K7hXy%2B");
WebDriverWait wait = new WebDriverWait(driver, 40);
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.xpath("//*[@id='WC_QuickInfo_Link_addtocart']")));
driver.findElement(By.xpath("//*[@id='WC_QuickInfo_Link_addtocart']"))
.click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.xpath("//input[@id='logEmail']")));
// Xls_Reader database1 = new Xls_Reader("D:\\Data.xlsx");
// String usernam= database1.getCellData("HWC", 1, 3);
driver.findElement(By.xpath("//input[@id='logEmail']")).sendKeys(
"tester3987");
// String Password =database1.getCellData("HWC", 2, 3);
driver.findElement(By.xpath("//input[@id='logPassword']")).sendKeys(
"Testing01");
driver.findElement(By.xpath("//*[@id='signIn']")).click();
Thread.sleep(1000);
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.xpath("//*[@id='termsA']/div/div[1]/div/div[1]/div[2]/h2[1]")));
// WebElement element = driver.findElement(By
// .xpath("//*[@id='termsA']/div/div[1]/div/div[2]"));
// Coordinates cor = ((Locatable) element).getCoordinates();
// cor.inViewPort();
// WebElement ele = driver.findElement(By
// .xpath("//*[@id='termsA']/div/div[1]/div/div[1]/div[2]/div[1]/p"));
// ((JavascriptExecutor) driver).executeScript(
// "arguments[0].scrollIntoView()", ele);
WebElement dragger1 = driver.findElement(By.xpath("//div[@class='jspTrack']/div"));
WebElement checkbox = driver.findElement(By.id("agreementAccept"));
System.out.println(checkbox);
driver.findElement(By.xpath("//p[@class='newsTitle']")).click();;
Robot robot = new Robot();
while(checkbox.getAttribute("disabled").equals("true")){
robot.keyPress(KeyEvent.VK_PAGE_DOWN);
checkbox.click();
}
}
}[/code:2y89utqk]