Problem in url navigate: Selenium and ChromeDriver [duplicate] - selenium

This question already has answers here:
pageLoadTimeout in Selenium not working
(2 answers)
pageLoadTimeout is not working in Selenium - Java
(2 answers)
How to make selenium to reload the desired url if it takes too long loading
(3 answers)
Closed 2 years ago.
I've got a question:
Below there is my java code for selenium to load a url in chrome browser:
chromedriver is 84.0.4147.30
Chrome version is also 84
public static int navigate(String data) {
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(driver, 30);
try {
driver.navigate().to(data);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("XPATH"));
....
}
What makes the automation:
when chrome is running the url is typed in the adreesbar and it loads the page.
But when the page is not loaded after 30 seconds, the function does not stop and aborts the test.
It waits endless.
I think it is the load sign in the page title tab that is the problem.
What can I do to abort the waiting when page is not loaded after 30 seconds?
Thanks in advance.

Related

Issue: .perform() method throwing MoveTargetOutOfBoundsException: Exception in Robotframework [duplicate]

This question already has answers here:
Selenium - MoveTargetOutOfBoundsException with Firefox
(9 answers)
MoveTargetOutOfBoundsException problem with chromedriver version >74
(2 answers)
Closed 2 years ago.
For .perform() method of ActionChains class we are facing exception “MoveTargetOutOfBoundsException: Message: move target out of bounds” frequently in application. Majorly found for mouse actions and click at coordinate on canvas element.
Scrolling we already tried and element is center of the screen still issue is observed
we are using robotframework==3.1, robotframework-seleniumlibrary==4.3.0, chrome=83.0.4103.61, chromedriver=83.0.4103.14

Selenium_Tab switching is not working in Safari browser [duplicate]

This question already has answers here:
Best way to keep track and iterate through tabs and windows using WindowHandles using Selenium
(1 answer)
Selenium switch focus to tab, which opened after clicking link
(3 answers)
Closed 2 years ago.
Still looking for resolution for following problem:
In Safari version 12: org.openqa.selenium.InvalidArgumentException: Request body does not contain required parameter 'handle'. I did see some solution saying use legacy, but not sure how to do that in selenium java.
Note: My code is working absolutely fine for Chrome, firefox, Edge browsers. I am facing this issue only with Safari.
Can anybody please help me here. Thanks in advance!
Selenium Version: 3.4/3.8
Code:
I am using Java for my scripts. Code:
String winHandleBefore = driver.getWindowHandle();
Set<String> windows = driver.getWindowHandles();
Assert.assertTrue("New browser window is not opened", windows.size() > 1);
for (String winHandle : driver.getWindowHandles()) {
String winHandleNew = winHandle;
if(!winHandleBefore.equalsIgnoreCase(winHandleNew)) {
driver.switchTo().window(winHandle);//THIS LINE GIVES THE ERROR
break;
}
}
driver.switchTo().defaultContent();

Selenium does not recognize an element in some of the times [duplicate]

This question already has answers here:
NoSuchElementException, Selenium unable to locate element
(3 answers)
Closed 4 years ago.
I have an element that selenium doesn't recognize sometimes.
I'm using implicitlyWait of 10 seconds and when i'm runing the test sometimes it passed succesfully and the element is recognized, and sometimes it failes with error "No such element".
I tried to change the wait time to 20 seconds but it dosen't matter
try using explicit wait :
WebDriverWait wait = new WebDriverWait(webDriver,60);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div/div/div/div/div[1]/div/div/a/i")));
I also faced this issue one time and I was facing this issue because I was was trying to select some option in the sub-menus using click to the main menu and then the sub-menu.
When used Actions class, the issue was resolved.
This could be an issue for you as well.

Clearing cache with Selenium ChromeDriver ChromeOptions [duplicate]

This question already has answers here:
How to clear browser cache in Selenium test
(3 answers)
Closed 5 years ago.
Currently using var driver = new ChromeDriver(TestContext.CurrentContext.TestDirectory);
We want to replace it as if we did:
With something like:
var options = new ChromeOptions();
options.AggressiveCacheDiscard = true; // how??
options.ChromeDriverDirectory = TestContext.CurrentContext.TestDirectory; // how??
var driver = new ChromeDriver(options);
But how do we do that? The goal being to set options that will ensure the cache/cookies are always cleared completely (From the beginning of time, as Chrome says) and that the directory is set.
There isn't a direct way to do this through Selenium. If you are trying to make sure everything is cleared at the beginning of starting a Chrome driver, or when you are done, then you don't need to do anything. Every time you initialize a webdriver, it is a brand new instance with no cache, cookies, or history. Every time you terminate the driver, all these are cleared.

Grid-Safari-Selenium is getting stuck on SafariDriver Launcher page[second Tab] by not closing it and NOT switching back to first Tab

Meta -
OS: OSX El capitan
Selenium Version: 2.53.0
Browser: Safari
Browser Version: 9.1
SafariDriver version: 2.48.0 which is latest as per SeleniumHQ site.
Expected Behavior -
SafariDriver Launcher page/tab should get closed automatically and get switched to first tab where my URL is getting opened.
Actual Behavior -
Selenium is getting stuck on SafariDriver Launcher page[Tab] by not closing it and switching back to first Tab
Steps to reproduce -
Trying to execute n number of test cases from TestNG.xml, but few TCs are getting executed properly by closing SafariDriver Launcher page[tab].
But for few cases Selenium is getting stuck on SafariDriver Launcher page[Tab] by not closing it and switching back to first Tab where my URL will get opened.
Required Solution -
I wanna first check how many tabs are currently opened by:-
if(browser.equals("safari")){
capability=DesiredCapabilities.safari();
capability.setBrowserName("safari");
capability.setPlatform(Platform.MAC);
capability.setVersion("9.1");
capability.setJavascriptEnabled(true);
driver=new RemoteWebDriver(new URL(grid_url),capability);
driver.get(url);
Thread.sleep(2000);
String windowHandle = driver.getWindowHandle();
ArrayList tabs = new ArrayList (driver.getWindowHandles());
if(tabs.size()>1){
<***Need a solution here to close second tab and switch to first tab***>
driver.switchTo().window(tabs.get(0));
}
}
You can use this code to close the window you want to :
for(String handle : driver.getWindowHandles()) {
if (!handle.equals(originalHandle)) { //the window handle you want to close
driver.switchTo().window(handle);
driver.close(); // would close the specific tab you wanted
}
}
In your case originalHandle could be the handle for the current window (tab 2) you are at.