Trying to use the ieDriver.switchTo().window(windowHandle) method to switch to a popup window but my test script stops and does not proceed.
When I close the window manually i get the error
org.openqa.selenium.NoSuchWindowException: Unable to get browser
I know the window exists because I used the ieDriver.getWindowHandles() method to retrieve it.
All my protected mode settings are the same, I even tried to use the 'INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS' technique to no avail. Any other suggestions?
I'm running selenium 2.32.0 with IE9 on a Windows 7 machine.
Above code isfor handling window pops.
If you want to handle javascript popups like alerts, or confrmation popup, you need to use
driver.SwitchTo.alert().accept();
or
driver.SwitchTo.alert().dismiss();
hope it'll help you
maybe the popup is generated, with iframe, then you have to use switchTo.frame();
You should do something like:
WebDriverWait webDriverWait= new WebDriverWait(driver, 5000);
webDriverWait.until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert().accept();
First you will initialize a WebDriverWait object that will allow you to wait until some condition is met, in this case - alert is present.
Then, the driver will be switched to this alert,
Related
I have this error "element not interactable" When I try to click a drop down list with selenium. However in debug mode, when I inspect ( press F12 ) before the break points and I continue to run then the test is passed. So my question is Why the elements can be clicked and what should I do to prevent the situation again. Many thanks!
You have to add wait / delay before accessing the elements to let the elements be fully loaded on the page before accessing them.
The simplest way is to add hardcoded sleep, like
time.sleep(5)
The better way is to use explicit way implemented by expected conditions.
Few things to note down,
Always launch browser in full screen mode.
driver.maximize_window()
this code should be written before driver.get()
Whenever you get element not interactable, try to use action chains to click or send_keys :
something like this :-
from selenium.webdriver.common.action_chains import ActionChains
action = ActionChains(driver)
action.move_to_element('your web element here').click().perform()
Make sure that using Selenium, the desired web element should be in Selenium view port.
in order to resolve this, you may have to scroll down to let Selenium know where exactly the element is.
I am writing an automated test and want to report bugs, if occur, directly in the repo at GitHub. The step which fails in my program is the Submit new issue button from GitHub Issue Tracker.
Here is the code:
WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));
sendIssue.click();
And the exception:
org.openqa.selenium.WebDriverException: Element is not clickable at
point (883, 547.7999877929688). Other element would receive the click:
div class="modal-backdrop"></div
The following command also does not work:
((JavascriptExecutor) driver).executeScript("arguments[0].click();", sendIssue);
How can I make it clickable? Is there any other way by which I can resolve this issue?
This is happening because when selenium is trying to click ,the desired element is not clickable.
You have to make sure that the Xpath provided by you is absolutely right.If you are sure about the Xpath then try the following
replace
WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));
sendIssue.click();
with
WebElement sendIssue =(WebElement)new WebDriverWait(DRIVER,10).until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button")));
sendIssue.click();
If that doesn't work ,You will get an Timeout exception, In that case try incaresing the timeout amount from 10 to 20.
If it still doesn't work please post a screenshot of the HTML.
You need to write something in the issue title and description to make the issue clickable are you sure you are not making that mistake of clicking the button without writing anything in those places I am adding screenshot for your convenience.
Selenium Webdriver introduced in a previous version (v2.48) a new behavior that prevent clicks on elements that may be overlapped for something else (a fixed header or footer - for example) or may not be at your viewport (visible area of the webpage within the browser window).
You can see the debate here.
To solve this you will need to scroll (up or down) to the element you're trying to click.
One approach would be something like this post:
Page scroll up or down in Selenium WebDriver (Selenium 2) using java
Another, and maybe more reasonable, way to create a issue on Github, would be using their API. Maybe it would be good to check out!
Github API - Issues
Gook luck.
This worked for me. Instead of HTML browser this would be useful if we perform intended Web Browser
// Init chromedriver
String chromeDriverPath = "/Path/To/Chromedriver" ;
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors");
WebDriver driver = new ChromeDriver(options);
I have a test where I need to click on a disabled button.
I am using the Actions class to do this.
When the user clicks on the button, an alert is generated.
Below is the code i have written:
Actions mouseActions = new Actions(driver);
mouseActions.moveToElement(driver.findElement(By.id("disabled_element_id"))).click().build().perform();
Then I try to switch to the alert I get exception:
Exception in thread "main" org.openqa.selenium.NoAlertPresentException: No alert is present.
You need to use JavaScriptExecutor for this task, WebDriver is not able to click on elements which are disabled or invisible. So try something like
JavascriptExecutor js = (JavascriptExecutor) webDriver;
js.executeScript("document.querySelector(\"button[id=yourButton]\").click()");
Selenium has been written to replicate user interaction, therefore will not allow interaction with disabled objects as a human would not be able to either.
you can either;
Replicate the process a user would do to enable a button.
Use JavaScript to enable or perform the interaction
I'm using phantomjs with selenium to click a button. Unfortunately, that button is disabled, and only enabled when there's mouseover/click event in the real browser. Is there any way to simulate that in PhantomJS?
I tried ActionChains, but it still doesn't work (the button is still disabled):
ActionChains(driver).move_to_element(button).perform()
I believe that your problem is not PhantomJS, but rather Actions. When you use actions, you should link all of your actions together, and then perform the action. In this case, it would be:
ActionChains(driver).move_to_element(button).click(button).perform();
Please try the following code:
browser.actions().mouseMove(element(by.css(button))).perform();
Selenium clickAt() function is throwing "Unsupported" exception while using with WebDriver (WebDriverBackedSelenium or just Selenium 2.x using ChromeDriver).
Is there any way to use this Selenium function via WebDriver?
Adding some code for context ...
ChromeDriver driver = new ChromeDriver();
driver.findElement(By.id("someID")).clickAt("25, 25");
.clickAt() method isn't even recognized ... however, using the WebDriverBackedSelenium is what provides the Unhandled exception.
You have to use Advanced User Interactions API
Click at the specific point inside an element looks like following:
ActionChainsGenerator builder = ((HasInputDevices) driver).actionsBuilder();
Action action = builder
.moveToElement(elementLocator, xOffset, yOffset)
.click()
.build();
action.perform();
At the moment, it is implemented for HtmlUnitDriver and InternetExplorerDriver only, other drivers are work in progress.
I have sometimes had similar problem and have fired the two MouseDownAt & MouseUpAt to solve the issue.. Seems as some JavaScript don't fire ok with clickAt always
Before you use click command on locator. you should use mouseOver on it.
Normally. this problem happen when link that need to click hidden or invisable.