I'm attempting to test the new 100.x.x.x changes using chrome://flags #force-major-version-to-100. After enabling it requires the browser to restart, I attempted to use driver.close() to do this but it doesn't save the change, so you're forced to use the button within chrome://flags to do so - once it reopens this way though, it has killed the instance. Is there a way to do this? I tried to setup ChromeOptions() for this, however I couldn't get it to enable experimental features.
The code I'm using is below.
#Test(enabled=true)
public void test() throws Throwable {
driver.get("chrome://flags/");
driver.findElement(By.xpath("//*[#id='search']")).sendKeys("force-major-version-to-100");
Thread.sleep(2000);
//driver.findElement(By.xpath("//*[#aria-labelledby='force-major-version-to-100_name']")).click();
Select dropdown = new Select(driver.findElement(By.xpath("//*[#aria-labelledby='force-major-version-to-100_name']")));
dropdown.selectByVisibleText("Enabled");
Thread.sleep(2000);
driver.findElement(By.xpath("//*[#id='experiment-restart-button']")).click();
Thread.sleep(3000);
driver.get("https://www.google.com");
Related
I'm trying to switch to a new window that will open when I login to the previous page. After clicking the login button a new tab will be open and gets closed immediately then a new window is open, this window handle is not recognized by the Selenium IE driver in IE MODE but I'm able to switch to this new window while automating in normal Internet Explorer browser. Selenium version is 4.3.0.0.
The code that I'd tried to switch to that new windows:
Thread.sleep(3000); // This delay is to avoid the new tab that gets closed immediately without this delay the driver is trying to switch to that new tab, after that any operation leads to throwing no browser exception. So this line is saving from the issue.
String desiredTitle = "";
while (!desiredTitle.contains("new window")) {
for (String ewh: driver.getWindowHandles()) {
desiredTitle = driver.switchTo().window(ewh).getTitle();
}
}
There're known limitations in Selenium 4 for IE mode automation. One of the workarounds suggests waiting until the driver gets the handle. You can try the sample code provided in that doc.
driver.get("MyURL");
System.out.println("URL is opened");
executeAutoItScript(scriptFileLocation);
when i open the URL i get an Authentication Required pop up.
To handle that I am using AutoIt script. But the problem is As soon as the first command
(driver.get("MyURL");)
is executed, Chrome will get open and the
Authentication pop up appears. And i have observed that the second line
System.out.println("URL is opened");
is not being executed. I debugged it and observed that the
control is not given to next line from
driver.get("MyURL");
and it hangs
there. I changed driver.get("MyURL"); to driver.navigate().to("MyURL"); but
there is no luck. Could anyone please help me to resolve this. Attached is
the pop up screenshot.
As per your code trials and the browser snapshot, it seems that the Browser Client (i.e. the Google Chrome Browser) is not returning back the control to the WebDriver instance and subsequently Selenium Java Client can't achieve the state of 'document.readyState' equal to "complete". Hence neither your next line of code:
System.out.println("URL is opened");
is getting executed, nor the AutoIt Script in next line:
executeAutoItScript(scriptFileLocation);
Solution
It is not clear from your question about the source of this Authentication Popup. Perhaps following the discussion Selenium - Basic Authentication via url you can pass the username and password being embedded within the URL as follows:
driver.get("http://admin:admin123#MyURL");
From: http://selenium-python.readthedocs.io/navigating.html
WebDriver will wait until the page has fully loaded (that is, the onload event has fired) before returning control to your test or script. It’s worth noting that if your page uses a lot of AJAX on load then WebDriver may not know when it has completely loaded. If you need to ensure such pages are fully loaded then you can use waits.
So, in this case your webpage is not fully loaded since it requires authentication. Here is what you can do
driver.get("MyURL");
executeAutoItScript(scriptFileLocation);
Thread.sleep(2000);// to wait for autoit script, you can also use other wait explicit wait
//Assert statement
System.out.println("URL is opened");
->First define the page load time for the driver.
->By using try-catch time out exception invoke the url.
->After that use robot class key events or key events class to enter the authentication details
Try the below one if any queries do lemme know:
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
try{
driver.navigate().to("yourURL");
}
catch(TimeoutException te){
System.out.println(te);
System.out.println("Line went to Upto that Link");
after this you could proceed with the authentication pop-up code.
Do lemme know if you have any queries.
This helped me:
InternetExplorerOptions options = new InternetExplorerOptions();
options.setCapability("initialBrowserUrl", "about:blank");
options.setPageLoadStrategy(PageLoadStrategy.NONE);
WebDriver driver = new InternetExplorerDriver(options);
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
driver.get(url);
//execute AutoItScript goes here
I want to kill the browser instance (chrome) that was opened by web driver previously. How would I do that? In my code below, I intentionally didn't want to include quit() or close() as I want to leave the browser open. So every time I execute or run this program, I want to kill/close the previously opened browser and then start a new instance and leave it on. As a result, only one instance of browser should be open at a time. I am using Mac.
public static void main(String[] args){
String website = "http://www.google.com";
System.setProperty(".....");
WebDriver driver = new ChromeDriver();
driver.get(website);
}
The behaviour atm is that everytime I execute this, chrome instance will just pile up. What is the best way to avoid this? I am not doing this for testing purpose. I'm doing this because I want to automate a task. Thanks.
You can try out this code :
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "D:\\Automation\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
try{
Runtime.getRuntime().exec("TASKKILL /F /IM chrome.exe");
}
catch(IOException io){
System.out.println(io.getMessage());
}
}
Note : It will kill all instances of chrome that was previously opened along with the newly opened instance.
If I understand correctly, you are trying to automate a part of the flow, then let the automation program exit leaving the browser open for completing rest of the steps manually. In this case, the best way to ensure only one such window is open would be to keep the automation script idling until you are done with with manual task. Something like this at end of your main function:
try {
while(true) {
Thread.sleep(1000);
driver.getCurrentUrl();
}
} catch(Exception e) {}
Would ensure that the program remains alive as long as the browser window is open. You can continue manual process in the browser. Once you are done, you can close the browser, which would automatically end this process. Or before starting the new task, you kill the old one with ^c, which in turn closes the browser.
The second option without keeping the automation script idling, would be to find the process id of newly created browser instance. You can save the process id in some file in temporary folder. Every time your script starts, it'd check the the file, read pid from it, and if the process id exists, try to kill it before spawning a new browser window.
[main] ERROR net.serenitybdd.core.Serenity - No alert is present
(WARNING: The server did not provide any stacktrace information)
My question is exactly similar to this one "Firefox alert box not detected with Selenium WebDriver"
But I am not able to find the solution. Even I have tried all kind of waits, changed Firefox versions and tried the solution mentioned in the shared link. But, either I am not able to implement it or its not working.
When doing this task manually pop up comes up when I click on update button and it's working fine.
But, when I do same action using automation pop-up shows and immediately closes automatically within a fraction of seconds and serenity throws error that No Alert not found. Also, alert window that appears during automation is bit different than the one found during manual execution. Please, refer to the link shared above if you want to see the difference in windows.
public void i_click_update_button() throws InterruptedException {
btn_update.waitUntilClickable().click(); // clicks the button & pop-up comes
}
public void Accept_POP_UP() throws InterruptedException {
getAlert().accept(); // code to accept the alret. I have already tried implementing wait & everything. problem is pop-up comes & immediately closes automatically
}
Have you switched the driver on the alert box
driver.switchTo().alert();
The classic google test here from selenium website, it works in FF on vista. On IE7, apparently doesn't find the window object. Selnm gets farther in the test (On IE) when I change config to using "*iexploreproxy", (instead of "*iexplore") but I cannot use that because it causes untrusted security certificate warnings. I installed selenium RC 1.0.1, and checked it is running on my box, I am not using any other tools such as bromine. I am running on Eclipse.
public class NewTest extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.google.com/", "iexplore");
// We instantiate and start the browser
}
public void testNew() throws Exception {
selenium.open("/");
selenium.type("q", "selenium rc");
selenium.click("btnG");
selenium.waitForPageToLoad("30000");
if(! selenium.isTextPresent("Results * for selenium rc"))
throw new Exception("failed");
}
}
I found this error to occur when IE was running in protected mode. You can disable protected mode by going to IE Tools->Internet Options->Security and click the check box.
I found that the internet options, connections, LAN settings has a automatic configuration script/custom profile that was interfering somehow in IE. It works now!
Here was the path just for history.
file://C:/Users/myname/AppData/Local/Temp/customProfileDir4b9b53c99d684ec4952cf8a721790c85/proxy.pac