I have tried everything to login into one site using Selenium webdriver java, but there is one "window", which I don't know how to call it , that I couldn't find one way to click in order to access it. Here, I open the firefox browser and lend on the parfumo.net webpage. The site loads "one window" with cookies settings...
public static void invokeBroser() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
NgWebDriver ngWebDriver = new NgWebDriver(js);
ngWebDriver.waitForAngularRequestsToFinish();
driver.get("https://www.parfumo.net");
driver.manage().window().maximize();
Thread.sleep(3000);
// Initialize and wait till element(link) became clickable - timeout in 60 seconds
WebDriverWait w = (WebDriverWait) new WebDriverWait(driver, Duration.ofSeconds(600));
w.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(),'Accept*')]")));
}
There is a Iframe you have to first switch to it like below
driver.switchTo().frame("iframeId");
OR
driver.switchTo().frame("iframeName");
Once you switch to the frame than perform the click like below.
public static void invokeBroser() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
NgWebDriver ngWebDriver = new NgWebDriver(js);
ngWebDriver.waitForAngularRequestsToFinish();
driver.get("https://www.parfumo.net");
driver.manage().window().maximize();
Thread.sleep(3000);
// Initialize and wait till element(link) became clickable - timeout in 60 seconds
WebDriverWait w = (WebDriverWait) new WebDriverWait(driver, Duration.ofSeconds(600));
driver.switchTo().frame("sp_message_iframe_737779");
w.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(),'Accept*')]")));
}
You can switch back to the main document like below:
driver.switchTo().defaultContent();
Related
I wonder how to safely quit the driver when the user closes the program while waiting for the element to appear.
`
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.addArguments("−−mute−audio");
WebDriver driver = new ChromeDriver(options);
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(Integer.MAX_VALUE));
driver.get(URL);
driver.findElement(By.xpath("/html/body")).click();
while (isAllowed) {
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div[class='alert-layout animated fadeIn v-enter-to']")));
//...
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div[class='alert-layout animated fadeIn v-enter-to']")));
}
LOGGER.info("quit selenium");
driver.quit();
`
I thought it would be solved by making isAllowed false at the end of the program, but it didn't.
How to do Resize using Java and Selenium?
Link
Code I have been trying:
public static void main(String[] args) throws InterruptedException
{
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
driver.get("https://jqueryui.com/resizable/");
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.switchTo().frame(0);
Thread.sleep(2000);
WebElement resize = driver.findElement(By.xpath("//div[#id = 'resizable']/div[3]"));
//WebElement resize = driver.findElement(By.id("resizable"));
new Actions(driver).dragAndDropBy(resize, 400, 400).perform();
}
the this is the below error:
> Exception in thread "main"
> org.openqa.selenium.interactions.MoveTargetOutOfBoundsException: move
> target out of bounds
The code that you'd shared earlier, I have made a few changes in that, Please see the below code.
The web element is in iframe, therefore we will have to first switch to the iframe and then use action class dragAndDropBy with the following properties:
(WebElement source, int xOffset, int yOffset)
Code:
driver.manage().window().maximize();
//driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.get("https://jqueryui.com/resizable/");
Actions action = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.demo-frame")));
WebElement resizeButton = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.ui-icon-gripsmall-diagonal-se")));
action.dragAndDropBy(resizeButton, 100, 50).build().perform();
When I tried to create an exemplar of WebdriverWait , I faced an issue with data types I believe. I can't setup seconds in the brackets because of it says that "ImplicitlyWait(long, java.util.concurrent.TimeUnit)' in 'org.openqa.selenium.WebDriver.enter image description hereTimeouts' cannot be applied to '(java.time.Duration)'
Please , see the code
public class ThirdClassHW3 {
WebDriver driver ;
WebDriverWait wait;
public void waitFirstMode() {
System.setProperty("webdriver.chrome.driver", "chromedriver 2");
driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
new WebDriverWait(driver, Duration.ofSeconds(10));
}
}
After the code clicks the action to login, the page gets refreshed and doesn't redirect to the next page. This only occurs for this website as I am redirected properly on other sites.
When I am giving the wrong credentials even the error message is not getting displayed.(Manually it works)
I am testing in Chrome with Selenium java.
Here is my code:
public class Test {
private static final String HTMLPageSourceCode = null;
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Selenium project\\chromedriver_win32/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://-----/tandem/login");
Thread.sleep(5000);
driver.manage().deleteAllCookies();
driver.findElement(By.id("login")).sendKeys("----");
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.findElement(By.id("password")).sendKeys("----");
WebElement loginbutton = driver.findElement(By.xpath(".//*[#id='login-button']"));
Actions actions = new Actions(driver);
actions.click(loginbutton).perform();
}
}
To login in into the website https://outhouse.inhouseusa.com/tandem/login/ you need to induce WebDriverWait for the elementToBeClickable() and you can use the following Locator Strategies:
Code Block:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
//options.addArguments("disable-infobars");
WebDriver driver = new ChromeDriver(options);
driver.get("https://outhouse.inhouseusa.com/tandem/login/");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.form-control#login"))).sendKeys("sandy");
driver.findElement(By.cssSelector("input.form-control#password")).sendKeys("sandy");
driver.findElement(By.cssSelector("input.pull-right.button.button-primary#login-button")).click();
I am trying to access the following site and get a registration pop up. In HTML it shows as form type. I tried handling as alert but it is not and I get exception as no modal dialog box opened. I tried window handles. The size of the window handles is only 1.
Please help me, so that, I can click on 'Signin' link on registration form and then login.
Website: http://way2automation.com/way2auto_jquery/index.php
System.setProperty("webdriver.gecko.driver", "C:\\mamtha\\Selenium Practice\\GeckoDriver\\geckodriver.exe");
String URL = "http://way2automation.com/way2auto_jquery/tooltip.php";
WebDriver driver = new FirefoxDriver();
driver.get(URL);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
Thread.sleep(3000);
Set <String> winhandle = driver.getWindowHandles();
System.out.println(winhandle.size());
WebElement sigin = driver.findElement(By.xpath("//a[contains(text(), 'Signin']"));
sigin.click();
driver.findElement(By.xpath("//input[#name = 'username']")).sendKeys("myusername");
driver.findElement(By.xpath("//input[#name = 'password']")).sendKeys("password");
driver.findElement(By.xpath("//input[#class = 'button']")).click();
Modal dialog box is getting opened in the same page itself.so, you don't want to use the window handles. You need to move the focus to the modal dialog box first and then directly access the required element(add some explicit wait condition as well).
Working Code:
System.setProperty("webdriver.gecko.driver", "C:\\mamtha\\Selenium Practice\\GeckoDriver\\geckodriver.exe");
String URL = "http://way2automation.com/way2auto_jquery/tooltip.php";
WebDriver driver = new FirefoxDriver();
driver.get(URL);
driver.manage().window().maximize();
//Explicit wait is added after the Page load
WebDriverWait wait=new WebDriverWait(driver,20);
wait.until(ExpectedConditions.titleContains("Welcome"));
WebElement modalDialogBox=driver.findElement(By.className("fancybox-skin"));
modalDialogBox.findElement(By.xpath(".//a[text()='Signin']")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("fancybox-skin")));
WebElement loginDialogBox=driver.findElement(By.className("fancybox-skin"));
loginDialogBox.findElement(By.name("username")).sendKeys("myusername");
loginDialogBox.findElement(By.name("password")).sendKeys("987654321");
loginDialogBox.findElement(By.className("button")).click();
Try the following code.
String URL = "http://way2automation.com/way2auto_jquery/tooltip.php";
WebDriver driver = new ChromeDriver();
driver.get(URL);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().window().maximize();
Thread.sleep(5000);
WebElement sign=driver.findElement(By.xpath("//p[#class='text_popup']/a[contains(text(),'Signin')]"));
sign.click();
Thread.sleep(5000);
driver.findElement(By.xpath("//div[#id='login']/form/fieldset[1]/input")).sendKeys("myusername");
Thread.sleep(5000);
driver.findElement(By.xpath("//div[#id='login']/form/fieldset[2]/input")).sendKeys("password");
driver.findElement(By.xpath("//div[#id='login']/form/div/div[2]/input")).click();