I have a dropdown which is hidden at the moment it loads and with a button click it is set to visible and I can see it when the selenium is running it in the browser but still it gives me this exception
org.openqa.selenium.WebDriverException: ElementNotVisibleError: Element is not currently visible and may not be manipulated'ElementNotVisibleError: Element is not currently visible and may not be manipulated' when calling method: [wdIMouse::click] Command duration or timeout: 47 milliseconds
Can someone suggest how we can resolve this?
Try using Actions and WebDriverWait
Maybe something like this
Actions builder = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver);
Action clickTheDropDown = builder.moveToElement(dd).Click(otherElement).build();
clickTheDropDown.perform();
wait.Until(Expectedcondition.VisibilityOfElement(dd);
Related
I have tried the following code but it is throwing the exception (ElementNotVisibleException)
FirefoxDriver dr = new FirefoxDriver();
dr.get("http://54.169.235.143/book.html?v=0.03");
System.out.println("First Testcase");
System.out.println(dr.findElement(By.id("user_name")));
dr.findElement(By.id("user_name"));
dr.findElement(By.id("user_name")).click();
dr.findElement(By.id("user_name")).getAttribute("user_name");
dr.findElement(By.id("user_name")).clear();
dr.findElement(By.id("user_name")).sendKeys("student100");
What am I doing wrong and how to fix it?
Actually your page taking time to load so web driver need wait until element gets visible , Below code will solve your issue :
WebDriverWait wait= new WebDriverWait(dr,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user_name")));
dr.findElement(By.id("user_name")).clear();
dr.findElement(By.id("user_name")).sendKeys("test");
wait= new WebDriverWait(dr,30);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("pass_word")));
dr.findElement(By.id("pass_word")).clear();
dr.findElement(By.id("pass_word")).sendKeys("test");
I have just added wait for elements.
n software testing services this can be achieved by many ways some of the options are displayed above remaining are as follow.
Using java script
driver.executeScript("document.getElementByXpath('element').setAttribute('value', 'abc')");
Using action class Actions actions = new Actions(driver);
actions.click(driver.findElement(element) .keyDown(Keys.CONTROL).sendKeys("a").keyUp(Keys.CONTROL).sendKeys(Keys.BACK_SPACE).build().perform());
I have some tests which click on a tab, however the click is not always performed.
The xpath is correct as most of the times the test works
It is not a timing issue as I ve used thread.sleep() and other methods to ensure that the element is visible before clicking
The test believes that it is performing the click as it is not throwing an ElementNotFoundException or any other exceptions when 'performing' the click. The test fails later on after the click since the tab content would not have changed.
Further Info
I am using Selenium 2.44.0 to implement tests in Java which run on Chrome 44.0.2403.107 m.
Is there something else that I can do or could this be an issue with selenium?
There are several things you can try:
an Explicit elementToBeClickable Wait:
WebDriverWait wait = new WebDriverWait(webDriver, 10);
WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.id("myid")));
button.click()
move to element before making a click:
Actions actions = new Actions(driver);
actions.moveToElement(button).click().build().perform();
make the click via javascript:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", button);
you can go with linkText if the tab name contains any unique string. And make sure your tab is not dynamic. It should be visible in source code(manual source code(ctrl+u)).
The following method work for me
WebElement button = SeleniumTools.findVisibleElement(By.cssSelector("#cssid"));
Actions actions = new Actions(driver);
actions.moveToElement(button).click().build().perform();
I have a similar problem. Tried all solutions from the top answer. Sometimes they work, sometimes don't.
But running code in an infinite loop works always.
For example, we need to click on element-two which is not visible until element-one is clicked.
WebDriverWait wait = new WebDriverWait(webDriver, 10);
while (true){
try {
WebElement elementOne =
wait.until(ExpectedConditions.elementToBeClickable(By.id("element-one")));
elementOne.click();
WebElement elementTwo =
wait.until(ExpectedConditions.elementToBeClickable(By.id("element-two")));
elementTwo.click();
break;
} catch (Exception e){
//log
}
}
I have a similar problem. Here is my solution:
table_button = driver.find_element(By.XPATH, insert your xpath)
try:
WebDriverWait(driver, 15).until(EC.element_to_be_clickable(table_button)).click()
except WebDriverException as e:
print('failed')
print(e)
Through code above, you can find the error message if your button is not clickable.
For example, my error message is 'nosuchelement' and 'clcik is not clickable', then I got back to check the table_button.accessible_name, found it print a 'null' value, so that means my XPATH is incorrect.
I have an element on a web page that only becomes visible after clicking its parent element. So after clicking a demo in a list of demo's, a row of icons which represent actions for the selected demo is revealed. The following code works fine with both webdriver and chromedriver:
demo.click(); //click demo
waitForElementIsDisplayed(demoReservation_btn); //wait until reservation icon is displayed
demoReservation_btn.click(); //click icon
Originally i was getting a StaleElementReferenceException and i attempted to fix this by having a try/catch block within a while loop that would continue looping until the icon was clicked. This caused IEDriverServer to crash after a couple of loops.
I have also tried wrapping it up in an Action like so:
Action action = new Action(driver);
action.click(demo).click(demoReservation_btn).build().perform()
This results in a NoSuchElementException.
I know there are some problems mentioned in the documentation about browser focus and hovering over elements, but i dont believe this is the problem. I have tried a couple of other things like adding moverToElement to the action, hovering over the element but have had no success with these. I believe one possible solution is to use a javascript executor, but i would like to avoid this approach if possible, any other suggestions?
EDIT
IEDriverServer setup:
File file = new File("IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
return driver;
Try disabling Native events of IE
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("nativeEvents",false);
driver = new InternetExplorerDriver(cap);
I had better result using that in C# version. Read this to learn why you may need to do this.
I am creating a test and having some issues. Here is the scenario. I use Selenium Web driver to fill out a form on Page1 and submit the form by clicking a button. Page2 starts loading... but the problem is, Page2 uses Google Analytics codes, and sometimes it takes forever for the page to stop loading.
Even though the expected element is already present, Selenium web driver does not proceed until the whole web page is fully loaded.
How do I make Selenium to move on to the next task or stop loading external javascript/css if the expected element is already present?
I tried tweaking the following settings but no luck.
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
TEMPORARY SOLUTION: Scroll below for answer!
Give below approaches a shot.
driver.findElement(By.tagName("body")).sendKeys("Keys.ESCAPE");
or
((JavascriptExecutor) driver).executeScript("return window.stop");
Alternatively, you can also use WebDriverBackedSelenium as shown in the snippet below from Vincent Bouvier.
//When creating a new browser:
WebDriver driver = _initBrowser(); //Just returns firefox WebDriver
WebDriverBackedSelenium backedSelenuium =
new WebDriverBackedSelenium(driver,"about:blank");
//This code has to be put where a TimeOut is detected
//I use ExecutorService and Future<?> Object
void onTimeOut()
{
backedSelenuium.runScript("window.stop();");
}
Source: https://sqa.stackexchange.com/a/6355
Source: https://stackoverflow.com/a/13749867/330325
So, I reported to Selenium about these issues. And the temporary workaround is... messing with Firefox's timeout settings. Basically by default Firefox waits about 250 seconds for each connection before timing you out. You can check about:config for the details. Basically I cranked it down so Firefox doesn't wait too long and Selenium can continue as if the page has already finished loading :P.
Similar config might exist for other browsers. I still think Selenium should let us handle the pagetimeout exception. Make sure you add a star to the bug here: http://code.google.com/p/selenium/issues/detail?id=6867&sort=-id&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary, so selenium fixes these issues.
FirefoxBinary firefox = new FirefoxBinary(new File("/path/to/firefox.exe"));
FirefoxProfile customProfile = new FirefoxProfile();
customProfile.setAcceptUntrustedCertificates(true);
customProfile.setPreference("network.http.connection-timeout", 10);
customProfile.setPreference("network.http.connection-retry-timeout", 10);
driver = new FirefoxDriver(firefox, customProfile);
driver.manage().deleteAllCookies();
Once you have checked for the element and you know that it is present, you could either navigate to/load a different page (if the next tasks are on a different page) or if the tasks are on the same page (as you anyway do not need the elements that have not yet loaded), you could continue as usual - selenium will identify the elements which have already been loaded. This works for me when I work with feature rich pages.
Instead of using the webdriver click() to submit the form use jsexecutor and do a click. Jsexecutor does not wait for page load and you can with other actions.
As per the above scenario explained i feel its best to use the below wait command in the first page.
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.id(>someid>)));
Once the required element is found in the first page next you can proceed to the second page.
As per the above scenario explained i feel its best to use the below wait command in the first page.
WebDriverWait wait = new WebDriverWait(driver, 10); WebElement element =
wait.until(ExpectedConditions.presenceOfElementLocated(By.id(>someid>)));
Once the required element is found in the first page next you can proceed to the second page.
Use explicit/webdriver wait----
WebDriverWait wt=new WebDriverWait(driver, 20);
wt.until(ExpectedConditions.elementToBeClickable(By.name("abc")));
"Register as new user" link text appears on home page , as soon as webdriver get it (driver.get) . But still it waits for entire page to load up to execute below line.
driver.findelement(By.linkText("Register as new user")).click();
how can it be possible that webdriver click on the element as soon as it appears on the page, no matter other elements appeared or not.
I am using: JAVA, Ubuntu.
I am not sure whether the implicit wait makes the driver wait till the page is fully loaded especially after opening an URL. But it is worth trying explicit wait. The below code makes the driver wait till the element becomes clickable then clicks on it. Should the element doesn't become clickable in the specified time(in the below example it is set to 30 seconds) then driver throws TimeoutException.
WebDriverWait wait = new WebDriverWait(driver, 30//unit time in seconds);
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Register as new user"))).click();
You can change the FireFoxDriver profile setting to make Firefox not wait for the full page to load after calling .click
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("webdriver.load.strategy", "unstable");
Bracket the wait.until ... statement like so:
turnOffImplicitWaits();
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Register as new user"))).click();
turnOnImplicitWaits();