I am using this code to launch Chrome with WebDriver.
System.setProperty("webdriver.chrome.driver","E://ChromeDriver//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://google.com");
Please help to open browser in current chrome session. Please use JAVA for solution
I have try this code to open new tab. #niazi, it will help you.
Code:
System.setProperty("webdriver.chrome.driver","F:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://google.com");
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,"t");
driver.findElement(By.tagName("body")).sendKeys(selectLinkOpeninNewTab);
Thread.sleep(2000);
ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs2.get(1));
driver.get("http://facebook.com");
WebDriver driver = new ChromeDriver();
It means open new Chrome browser. Once you have to open new browser window.
EDIT as per your comment
System.setProperty("webdriver.chrome.driver","F:\\chromedriver.exe");
WebDriver driver = new ChromeDriver(); driver.manage().window().maximize();
driver.get("http://google.com");
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,"t");
driver.findElement(By.tagName("body")).sendKeys(selectLinkOpeninNewTab);
Thread.sleep(2000);
ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs2.get(1));
driver.get("http://facebook.com");
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.
I am using the code mentioned below but it is not working Chrome Version 79:
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
//capability.setCapability("pageLoadStrategy", "none");
System.setProperty("webdriver.chrome.driver","driver//chromedriver.exe");
driver = new ChromeDriver(capability);
//driver.manage().deleteAllCookies();
driver.manage().window().maximize();
//Runtime.getRuntime().exec("AutoIT_Exe//AutoIT_Login.exe");
driver.get(url);
You can use switches to ignore such errors
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--ignore-certificate-errors"));
driver = new ChromeDriver(capabilities);
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();
Yesterday Internet Explorer got updated (11.0.44 update), then below code prompts me with the following error not able to get browser.
I have set HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE key of iexplore.exe with 0.
Anyone can help me out?
Code:
String IEDriver_64 = "D:/Tools/IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", IEDriver_64);
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true);
WebDriver driver = new InternetExplorerDriver(capabilities);
//capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
String baseUrl = "https://xxx//member/login.php";
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get(baseUrl);
Thread.sleep(1000*30);
System.out.print("driver.getCurrentUrl()1="+driver.getCurrentUrl());
System.out.print("driver.getTitle()1="+driver.getTitle());
System.out.print("-------------1-------------");
String currenthandle = driver.getWindowHandle();
System.out.print("-------------2-------------");
System.out.print("currenthandle="+currenthandle);
Thread.sleep(1000*5);
driver.findElement(By.id("SUBMIT_LOGIN")).click();