Selenium contextClick() hangs on Edge browser - selenium

System.setProperty("webdriver.edge.driver","C:\\EdgeDriver\\" + "MicrosoftWebDriver.exe");
WebDriver driver = new EdgeDriver();
driver.navigate().to("http://www.google.com");
new Actions(driver).moveToElement(driver.findElement(By.id("lst-ib"))).contextClick().build().perform();
if (driver != null) {
driver.close();
}
When I run the above code, a context menu is popped up, but it does not proceed further from that. If I manually click on somewhere else, it proceeds further into the program.
I have checked with other browser/driver, it works without any
problem.
I am using Selenium 2.53 and MicrosoftWebDriver 14393
Any solution for this?

try System.setProperty("webdriver.edge.driver","C:\EdgeDriver\MicrosoftWebDriver.exe");
instead of
System.setProperty("webdriver.edge.driver","C:\EdgeDriver\" + "MicrosoftWebDriver.exe");

Related

Selenium Node driver.manage().window().setPosition(new Point(X,Y)); Not having any effect

So I am running a simple enough Selenium program through the GRID.
I have Grid and Node all setup working perfectly.
The issue I am having is with the below :
driver.manage().window().setPosition(new Point(X,Y));
This appears to have zero effect on the browser on the node machine. Looking at the server this command is understand and even processed without error :
14:57:02.811 INFO - Done: [set window position]
14:57:11.318 INFO - Executing: [get window position])
Code used was
driver.manage().window().setPosition(new Point(600, 500));
I inserted some code to get the cords of the browser, and they are returned as :
System.out.println(" POSITION " +driver.manage().window().getPosition());
RESULT = "POSITION (600, 500)"
I am using the "import org.openqa.selenium.Point;" import.
There are not other issues with the code.
The reason I need to move the browser , is because a second browser keeps overlapping the first browser , thus making it impossible for Selenium to interact with the first browser (I am using the parallel testing . I resized both browsers to try and fix the issue. Incidentally, there is no issue at all with the resize code (below) that works perfectly :
driver.manage().window().setSize(new Dimension(600, 500));
FULL CODE :
DesiredCapabilities cap = DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL(Node), cap);
// Puts an Implicit wait, Will wait for 10 seconds before throwing
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// Launch website
driver.navigate().to(URL);
driver.manage().window().setSize(new Dimension(600, 500));
driver.manage().window().setPosition(new Point(600, 500));

Opening a new tab in the same window session of the browser through Selenium WebDriver?

How to open a new tab in the same window session of the browser through Selenium WebDriver command?
Opening a new tab in the same browser window is possible, see solutions for Firefox:
How to open a new tab using Selenium WebDriver with Java?
Controlling firefox tabs in selenium
The problem is - once you've opened a tab, there is no built-in easy way to switch between tabs. Selenium simply doesn't provide an API for that.
Instead of a tab, open a new browser window.
Yes you can do that , See below my sample code for that :
//OPEN SPECIFIC URL IN BROWSER
driver.get("http://www.toolsqa.com/automation-practice-form/");
//MAXIMIZE BROWSER WINDWO
driver.manage().window().maximize();
//OPEN LINKED URL IN NEW TAB IN SAME BROWSER
String link1 = Keys.chord(Keys.CONTROL,Keys.ENTER);
driver.findElement(By.linkText("Partial Link Test")).sendKeys(link1);
Above code will open link1 in new tab. you can run above code to see effect. Above is public link includes testing form.
But as #alecxe told that there is no way to switch between tabs. So better you open new browser window.
Using java script we can easily open new tab in the same window.
public String openNewTab(){
String parentHandle = driverObj.getWindowHandle();
((JavascriptExecutor)driverObj).executeScript("window.open()");
String currentHandle ="";
// below driver is your webdriver object
Set<String> win = driver.getWindowHandles();
Iterator<String> it = win.iterator();
if(win.size() > 1){
while(it.hasNext()){
String handle = it.next();
if (!handle.equalsIgnoreCase(parentHandle)){
driver.switchTo().window(handle);
currentHandle = handle;
}
}
}
else{
System.out.println("Unable to switch");
}
return currentHandle;
}
I am afraid, but there is a way to switch between tab's .
We have successful answers for this problem.
Please find the below link.
switch tabs using Selenium WebDriver with Java
Selenium can switch between tabs.
Python:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
element = driver.find_element_by_css_selector("html") # Gets the full page element, any element works for this
key_code = Keys.CONTROL # Use Keys.COMMAND for Mac
driver.execute_script("window.open();") # Executes Javascript to open a new tab
driver.switch_to.window(1) # Switches to the new tab (at index 1, first tab is index 0)
driver.switch_to.window(0) # Switches to the first tab

Selenium Webdriver (C#): Drag and Drop executed but nothing happens

I am unable to drag and drop the W3Schools image into the rectangle using the example code people have given before. I've tried Firefox, Chrome and IE webdrivers, nothing is happening.
Firefox version 26.0
Chrome version: 31.0.1650.63 m
Internet Explorer version: 11
FirefoxDriver browser = new FirefoxDriver(); //Open up a Firefox browser
browser.Url = "http://www.w3schools.com/html/html5_draganddrop.asp";
System.Threading.Thread.Sleep(5000); // Wait so I can see what's happening
IWebElement imageToDragAndDrop = browser.FindElementById("drag1");
IWebElement boxToDragImageInto = browser.FindElementById("div2");
Actions actions = new Actions(browser);
// Attempt 1: Calling the DragAndDrop method did not work
// actions.DragAndDrop(imageToDragAndDrop, boxToDragImageInto).Build().Perform();
// Attempt 2: Calling the DragAndDrop method again but with the method calls on separate lines
//actions.DragAndDrop(imageToDragAndDrop, boxToDragImageInto);
//actions.Build();
//actions.Perform();
// Attempt 3: Calling the ClickAndHold, MoveToElement, Release methods did not work either
actions.ClickAndHold(imageToDragAndDrop);
actions.MoveToElement(boxToDragImageInto);
actions.Release(imageToDragAndDrop);
actions.Build();
actions.Perform();
HTML5 drag and drop is a known issue for Selenium;
https://code.google.com/p/selenium/issues/detail?id=6315&thanks=6315&ts=1380031813
Try using javascript directly as explained here;
HTML5 Drag and Drop using Selenium Webdriver for Ruby

KeyPress Enter for Selenium

We are doing automation testing and came around with a situation where i need to download the file from the browser .
In Download when the download button is hit we are coming to the system pop for the download where we need to perform the enter operation .
Can some one help us how to perform the enter or keyboard operation currently we are using robot API but it is not working on grid system ,
Here is my code for robot can it be enhanced and used or do we have any alternate way to do it
******** Code *************
public void downloadReportFromMyExport(WebDriver driver, String downloadSufixId) throws AWTException,
InterruptedException
{
String downloadPrefixId = ConfigProperty.getConfig("downloadPrefixId").trim();
String[] suffix;
suffix = StringUtil.split(downloadSufixId, "TR_EXP_");
String suffixPart = suffix[0];
String completeId = downloadPrefixId.concat(suffixPart);
By id = By.id(completeId);
WebElement element = driver.findElement(id);
element.click();
Robot pressKey = new Robot();
pressKey.keyPress(KeyEvent.VK_ENTER);
pressKey.keyRelease(KeyEvent.VK_ENTER);
threadSleep("5");
pressKey.keyPress(KeyEvent.VK_ALT);
pressKey.keyPress(KeyEvent.VK_F4);
pressKey.keyRelease(KeyEvent.VK_F4);
pressKey.keyRelease(KeyEvent.VK_ALT);
logger.info("Downlaod Complete");
}
In firefox browser,
Solution-1
You can change the browser settings so that it saves all downloads to that location without asking.
Refer below link to know to change that setting in firefox.
https://support.mozilla.org/en-US/kb/startup-home-page-download-settings
Solution-2
By using firefox profile setting you can achieve this.
FirefoxProfile profile=new FirefoxProfile();
profile.setPreference("browser.download.folderList",2);
profile.setPreference("browser.download.manager.showWhenStarting",false);
profile.setPreference("browser.download.dir","C:\\Users\\Downloads\\"); profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver=new FirefoxDriver(dc);
yeah i've encountered the same issue
better change the browser settings to save in a particular path
for handling different browsers like,
in FF,
i've used
in firefox by default the control will be on "OPEN" option so..
Robot robot=new Robot();
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
for IE (to save alt+s,to open alt+O) here im saving the file
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
robot.keyRelease(KeyEvent.VK_S);
for chrome
by default,when ever you click dowload button it will save without showing any popups
and i've succeeded hope it helps you
-Ajay

Mouse hover on element

http://www.franchising.com/ ---> Mouse over on (Franchises A-Z) ---> need to click Q
I have tried with the following
WebElement we1=driver.findElement(By.cssSelector("a[href='/franchises/']"));
WebElement we2=driver.findElement(By.cssSelector("a[href='/franchises/q.html']"));
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
((JavascriptExecutor) driver).executeScript(js, we2); // I have used the script since the we2 is not visible
Actions builder=new Actions(driver);
builder.moveToElement(we1).perform();
Thread.sleep(5000);
we2.click();
could any one try and share me the code... Still I'm getting "ElementNotVisibleException"
With firefoxdriver, a lot would depend on what version of driver you are using and what version of Firefox you have on your system since native support would differ based on that.
Following works on Chrome :
WebElement link1 = driver.findElementByLinkText("Franchises A-Z");
Actions action = new Actions(driver);
action.moveToElement(link1).click(driver.findElementByXPath("//a[contains(#href,'franchises/b')]")).perform();
Before going in to the code i just want to you to ensure the version of Selenium server you are using. Please make it to the updated version of 2.28.x
Code:
driver = new FirefoxDriver();
driver.get("http://www.franchising.com/franchises/");
Thread.sleep(5000);
WebElement element=driver.findElement(By.xpath("//tr[3]/td/table/tbody/tr/td[4]/a"));
Actions builder = new Actions(driver);
builder.moveToElement(element).build().perform();
Thread.sleep(5000);
it works fine for me. Try this code. I hope this will work.