Dismiss an alert selenium webdriver
Alert alert = wait.until(alertIsPresent()); alert.dismiss();
Alert alert = wait.until(alertIsPresent()); alert.dismiss();
//Update to HttpClientBuilder (import org.apache.http.impl.client.HttpClientBuilder) import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.HttpClientBuilder; public class Test { public static void main(String[] args) throws Exception { HttpClient client = HttpClientBuilder.create().build(); HttpPost post= new HttpPost(URL); HttpResponse response = client.execute(post); System.out.println(response.getStatusLine().getStatusCode()); } }
Alert alert = driver.switchTo().alert(); try { alert.getText()); } finally { alert.accept(); }
This is due to missing the chrome driver path with the node. So in machine A Run hub java -jar lib/selenium-server-standalone-2.44.0.jar -role hub In machine B register node with parameter -Dwebdriver.chrome.driver so the command should be something like this. C:\Users\Admin\Downloads>java -jar selenium-server-standalone-2.44.0.jar -role w ebdriver -hub http://A-MachineIP:StandaloneRunningPort/grid/register -Dwebdriver.chrome.driver=Path of downloaded binary in B machine. C:\Users\Admin\Downloads>java […]
package com.seleniumproject; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.events.EventFiringWebDriver; public class Scroll { public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = new FirefoxDriver(); EventFiringWebDriver efD = new EventFiringWebDriver(driver); efD.get("http://localhost:8081/web/alerts.html"); efD.executeScript("scroll(0,2000)"); } }
For below example you have to use xpath with name space. <!DOCTYPE html> <html><body> <div id="overview-layout"> <div id="overview-body"> <div class="" id="overview-tabcontent-container"> <div data-highcharts-chart="7" class="chart" id="chart_1"> <div id="highcharts-26" class="highcharts-container"> <svg height="304" width="1154" version="1.1" xmlns="http://www.w3.org/2000/svg"> <rect zIndex="1"></rect> <path zIndex="2"></path> <g transform="translate(73,0)" style="cursor:default;text-align:center;" zIndex="7" class="highcharts-button"> <rect stroke-width="1" stroke="#68A" height="18" width="30" y="0.5" x="0.5" fill="url()" ry="0" rx="0"></rect> <text zIndex="1" y="14" […]
WebDriverWait wait; Alert alert = wait.until(alertIsPresent()); alert.accept();
In A machine run your driver code, given below. import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; public class RemoteDriver { private WebDriver driver = null; @Test public void myTest() throws IOException, InterruptedException { driver.get("http://www.google.com"); } @Before public void createDriver() throws MalformedURLException { DesiredCapabilities capability = DesiredCapabilities.firefox(); […]
import java.io.IOException; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class waitForMultipleElements { WebDriver driver = new FirefoxDriver(); public boolean isElementPresent(By by) { try { driver.findElements(by); return true; } catch (org.openqa.selenium.NoSuchElementException e) { return false; } } public void waitForMultipleElementsPresents(By[] by, int time) throws InterruptedException { int length = by.length; for (int i = […]
use http username and http password before @ and parse it through url. driver.get("http://username:password@www.example.com");