I am trying to open a new tab using Selenium Webdriver and Java, and have used the below code, but it is not opening any new tab and no error message is displayed during the run.
Actions act = new Actions(driver);
act.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).build().perform();
Using the above code I am trying to open a new tab by pressing CTRL+T from keyboard. Please help me.
try this
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
driver.findElement(By.linkText("urlLink")).sendKeys(selectLinkOpeninNewTab);
or use
((JavascriptExecutor)driver).executeScript("window.open();");
Related
I have to click on chrome Extensions button present in address bar in web automation project.
I have no clue how I can click on it using Selenium Webdriver.
Please check attached screen shot for your reference.
Below code snippet which I am using, but not sure click I can click on Extensions button?
System.setProperty(
"webdriver.chrome.driver",
"D:\\drivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions ();
options.addExtensions (new File("D:\\CRX-Extractor-Downloader.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
driver.manage().window().maximize();
driver.get("https://www.google.com");
Thread.sleep(5000);
You can assign a shortcut to the extension you want to click. For example, after = 'CTRL + U' you can send it with sendkeys while the test automation is running on the page.
How to Open Extensions With a Keyboard Shortcut in Any Browser
= https://www.makeuseof.com/open-browser-extensions-keyboard-shortcut/
I am creating some data and click on Save button. Manually when i do it there is no popup at all. But in automation browser of chrome i could see a popup appears asking to stay in page or leave page. How can i avoid the popup in automation script?
As per my knowledge, we have to create profile for chrome driver. I used the below whicc is not working for me. Can someone plssss plssss help me out on this
String userProfile= "C:\\Users\\user_name\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\";
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir="+userProfile);
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");
is there any specific reason that you are using ChormeOptions?
You can simply use the below code, and it'll work fine and no popups.
System.setProperty("webdriver.chrome.driver","pathToChromeDriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
I need a solution to download a PDF file from an web application in IE11 using selenium webdriver. Please find the below pop-up which I am trying to handle.
Below are the ways I tried handle the IE popup but unfortunately nothing helped.
I tried to handle this scenario using AutoIT using the below AutoIT script.
Sleep(5000)
Local $hIE = WinGetHandle("[Class:IEFrame]")
Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")
If WinExists($hIE,"") Then
WinActivate($hIE,"")
ControlSend($hIE ,"",$hCtrl,"{F6}")
Sleep(500)
ControlSend($hIE ,"",$hCtrl,"{TAB}")
Sleep(500)
ControlSend($hIE ,"",$hCtrl,"{enter}")
EndIf
Sleep(25000)
Though the above AutoIT script worked, but after execution of AutoIT script the webdriver scripts hangs up. Even a common system.out.println statement is not getting executed after handling the pop-up using above AutoIT script.
I tried to handle this pop-up using Robot class, but hard luck, that also not seems to be working.
I tried to disable this IE pop-up by doing some registry settings by going to the below path,
HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\AttachmentExecute\
After doing certain registry settings, this pop-up is successfully getting disabled for .xlsx or .RDP files and not for .PDF files. But In my case I have a test case where I need to download a .pdf file and proceed with further webdriver scripts.
Guys, suggestion of any other workaround will be greatly appreciated.
Thank you,
Sudheendran P L
I had the same problem. Click button does not work properly in this case with IE. I switched clicking button for focusing it with sendKeys() and then pressing with Enter.
Try this:
Robot robot;
try {
// pressing download button
button.sendKeys("""");
robot = new Robot();
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
// handling download
webDriver.wait(2000);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_S);
webDriver.wait(200);
robot.keyRelease(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_ALT);
} catch (Exception e) {
e.printStackTrace();
}
You can use Thread.sleep() instead of driver.wait() and should work as well.
How to automate Adobe PDF web forms (XFA) using selenium web driver ? How to inspect elements in order to input text or click submit button in PDF forms ? These pdf forms are only supported by IE and no other browsers
Selenium Webdriver can only perform operations on DOM.
Can you right click on the form and see if view source option is coming?If not,then i don't think you can input anything on your Adobe PDF using Selenium Webdriver.
You can't automate PDF file but yes you can verify any text any content in PDF file. You can try below code if it met your requirement
Try below code:-
public void ReadPDF() throws Exception {
URL TestURL = new URL("http://www.axmag.com/download/pdfurl-guide.pdf");
BufferedInputStream TestFile = new BufferedInputStream(TestURL.openStream());
PDFParser TestPDF = new PDFParser(TestFile);
TestPDF.parse();
String TestText = new PDFTextStripper().getText(TestPDF.getPDDocument());
Assert.assertTrue(TestText.contains("Open the setting.xml, you can see it is like this"));
}
Download libraries :- https://pdfbox.apache.org/index.html
Hope it will help you :)
I am trying to add a new tab using Webdriver 2.0 in Chrome but couldn't get the result.I have followed few answers provided in different forums.As I am very new to java and the answers available are more specific to Java scripting,I have posted this query to get a simple solution if possible.
E.g : The following statement is not triggering any action but the result in Selenium shows pass. Please advise.
driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL +"t");
When you can open a chrome window using
WebDriver driver = new ChromeDriver();
You can simply open a new window using
WebDriver driver2=new ChromeDriver();
You can access driver and driver2 in parallel or sequential.
To close a window do driver.close();
With the latest versions of selenium you can create a new tab, the line in the official github repo.
In C# is something like this:
ChromeDriver driver = new ChromeDriver();
driver.SwitchTo().NewWindow(WindowHint.Tab);
here is the junit test of java for creating a new tab