The following is my code. One browser opens blank and another opens google.
I am using the latest version of chrome driver. Thanks in advance.
public class Trials {
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com");
Thread.sleep(3000);
driver.close();
}
}
Related
`
public class CucumberHooks {
public static void main(String[] args) {
}
protected static WebDriver driver;
#Before
public void setup() throws IOException {
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("extension_5_3_2_0.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
String browser = ReadPropertyFileSingleton.getInstance().getProp("browser");
driver = Util.setEnvironmentAndGetDriver(browser);
assert driver != null;
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
public static WebDriver getDriver() {
return driver;
}
#After
public void close() {
driver.quit();
}}
The code where I added adblock extensions via crx file
When I run tests through a feature file, a regular browser without a blocker is launched
the browser is also launched already with a blocker, but it does not see the steps
what could be the problem and is it possible to use adblock this way?
public class AutoITDemo {
public static void main(String[] args) throws IOException, InterruptedException {
test();
}
public static void test() throws IOException, InterruptedException {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://ps.uci.edu/~franklin/doc/file_upload.html");
driver.findElement(By.name("userfile")).click();
//calling AutoIT script
Runtime.getRuntime().exec("D:\\seleniumTests\\inprogress\\AutoIT\\FileUoloadScript.exe");
Thread.sleep(3000);
driver.close();
}
}
I am trying to go to this URL "https://ps.uci.edu/~franklin/doc/file_upload.html" and upload a file using AutoIT by clicking on the button. But the upload button is not clicked and the following Exception prints on the console. How to solve this?
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: invalid argument
(Session info: chrome=89.0.4389.128)
screen shot
See if this works:-
WebElement browse = driver.findElement(By.xpath(".//input[#name='userfile']"));
browse.sendKeys("File path you want to upload");
public class TestTabs {
public WebDriver driver;
public WebDriver getDriver() {
return driver;
}
#Before
public void setUp() throws Exception {
System.setProperty("webdriver.gecko.driver","/Users/Test/Downloads/geckodriver");
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
//driver.findElement(By.cssSelector("body")).sendKeys(Keys.COMMAND+ "t");
}
#Test
public void openSameUrlInMultipleTab() throws InterruptedException {
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://seleniumlearn.com/selenium-tutorial");
{
driver.findElement(By.cssSelector("body")).sendKeys(Keys.COMMAND+ "t");
driver.get("https://www.facebook.com");
}
}
}
I am using the above code to open multiple tabs in one browser but When I am running this code in Firefox (iMac mini) I am not getting any error message and code is passed but 2nd link is opening in same tab rather than in new tab. How can I open multiple tabs in Firefox in Mac?
Each tab is considered as a new window. switch to the new tab using the switch.to().window().
driver.switchTo().window(winHandle);
driver.get("your new url goes here");
User below line if you want to switch to default browser (the base browser).
driver.switchTo().defaultContent();
public class chrome {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://neontv.co.nz");
Thread.sleep(2000);
driver.findElement(
By.xpath("//*[#class='nv-nav-freetrial-2 nv-nav-item']"))
.click();
Thread.sleep(200);
driver.findElement(
By.xpath("//ul[#id='yui_patched_v3_11_0_2_1529643447183_22']"))
.click();
Thread.sleep(2000);
driver.quit();
}
}
I am unable to select package on next page.. I tried changing the xpath but it didnt help.. is there any other way to select this. Could any one help please
Using Action classes, I was able to resolve this
driver.switchTo().defaultContent();
Actions action = new Actions(driver);
action.moveToElement(btnEnjoy).click().build().perform();
I had tried to run below JUnit (Selenium WebDriver) test case to open Google in Chrome browser, but it is failing with error message as
"The path to the ChromeDriver executable must be set by the
webdriver.chrome.driver system property; for more information, see
http://code.google.com/p/selenium/wiki/ChromeDriver."
As specified in that website, I downloaded ChromeDriver.exe but don't know,
Which PATH should I place that? or
How to set ChromeDriver path in webdriver.chrome.driver?
Please Advise.
My JUnit test case (changed the Firefox Driver to Chrome Driver):
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
public class Chrome_Open_Google {
private WebDriver driver;
private String baseUrl;
#Test
public void Test_Google_Chrome() throws Exception {
driver = new ChromeDriver();
baseUrl = "http://www.google.co.uk/";
driver.get(baseUrl);
}
#After
public void tearDown() throws Exception {
driver.quit();
}
}
I believe you have several options:
Either specify the folder (in which your chromedriver binary is) in your PATH system variable - here's how
Or give you application webdriver.chrome.driver as a system property by calling it with -Dwebdriver.chrome.driver=the/path/to/it parameter.
Or the same programatically: System.setProperty("webdriver.chrome.driver", "your/path/to/it");
Or this:
private static ChromeDriverService service;
private WebDriver driver;
#BeforeClass
public static void createAndStartService() {
service = new ChromeDriverService.Builder()
.usingChromeDriverExecutable(new File("path/to/my/chromedriver"))
.usingAnyFreePort()
.build();
service.start();
}
#Before
public void createDriver() {
driver = new RemoteWebDriver(service.getUrl(), DesiredCapabilities.chrome());
}
#After
public void tearDown() throws Exception {
driver.quit();
}
#AfterClass
public static void createAndStopService() {
service.stop();
}
System.setProperty("webdriver.chrome.driver", "your\path\to\it");
For Eg :
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\driver\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();