I need to give a input text file in GWT FileUpload and test it using Selenium Webdriver.
I have Upload widget, In that I need to give a text file as input. Then click a upload button to do my functionality.
i tried this,
driver.findElement(By.id("uploadField")).sendKeys("C:/Desktop/Input.txt");
driver.findElement(By.id("uploadButton")).click();
but I'm not able to give input to this upload field.
Can anyone help me?
See this code is working for me see : use correct file path in sendkeys
driver.get("http://www.freepdfconvert.com/");
driver.findElement(By.id("UploadedFile")).sendKeys("C:\\Users\\username\\Downloads\\HP1.pdf");
try {
Thread.sleep(4000);
}
catch (Exception e) {}
driver.findElement(By.name("pdfsubmit")).click();
}
or
driver.findElement(By.id("uploadField")).sendKeys("C:/xyz.txt");
driver.findElement(By.name("uploadButton")).click();
Use name or Xpath then check .
Edit
Yes it run for all browser but for IE and chrome you have to add small code.
IE:
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
Chrome
File file = new File("E://chromedriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();`
Related
Just getting started with Katalon Recorder. After navigating and loading a page, is there a way to store the entire page text? I am trying to automate a function where I have to click into a list item, select all, copy and paste into excel.
The comment from Mate Mrše is off to a good start. Here's some example code that fleshes out the details. The following code saves the page to an html file. From there you'll need additional processing to put it into another document format, such as Excel.
// add the following two imports for the webdriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.WebDriver as WebDriver
// open browser/navigate, etc
// WebUI.openBrowser('https://google.com')
WebUI.delay(5)
WebDriver driver = DriverFactory.getWebDriver()
def src = driver.getPageSource()
def file1 = new File('c:/1/the_saved_web_page.htm')
file1.write(src)
Editor templates in eclipse can be imported from xml file. Instead of manually importing, wanted to create a plugin. Which will import the templates.xml kept in specified folder at start of the eclipse.
How this can be achieved?
You can use the JFace org.eclipse.jface.text.templates.persistence.TemplateReaderWriter to read a template.xml. Something like:
File file = .... file to read
TemplateReaderWriter reader = new TemplateReaderWriter();
InputStream input = new BufferedInputStream(new FileInputStream(file));
TemplatePersistenceData[] datas = reader.read(input, null);
(code to deal with errors and closing the input left out)
You can then put the data in a TemplateStore:
TemplateStore fTemplateStore = ... store to use
for (TemplatePersistenceData data: datas) {
fTemplateStore.add(data);
}
fTemplateStore.save();
The template store you use depends on which templates you are updating.
For the Java Editor template store you can get the store with
JavaPlugin.getDefault().getTemplateStore();
But the JavaPlugin is not part of the official Eclipse API.
The above code is a simplified version of the import code in org.eclipse.ui.texteditor.templates.TemplatePreferencePage
Test env: Capybara,poltergeist, phantomjs.
A new window opens up when I click a link in my test case. I was able to switch to the new window and verify text using selenium driver. However, I am unable to switch to the new window with poltergeist. I tried the following method to switch to the new window and none of them worked.
I wanted to see if a new browser is getting open at all and looks like it is.
main = page.driver.browser.window_handles.first
puts main (gives 0)
popup = page.driver.browser.window_handles.last
puts popup (gives 1)
1. within_window(->{ page.title == '2015-11-5.pdf' }) { assert_text(facility_name) }
2. page.switch_to_window(window=popup)
3. page.switch_to_window(page.driver.browser.window_handles.last)
4. page.driver.browser.switch_to().window(page.driver.browser.window_handles.last)
Could someone provide any inputs here? Thanks!
I used the following and the popup is getting generated and the control switches to it.
page.switch_to_window(page.window_opened_by{click_link('Generate Report')})
The new window has a pdf embedded in it.I was able to read and verify the contents of the document when I use selenium driver. With poltergeist, I am unable to read the pdf. Could you give me some pointers on how to proceed?
Capybara has a number of cross driver methods for dealing with this without having to go to driver specific methods.
popup = page.window_opened_by {
click_link('whatever link opens the new window')
}
within_window(popup) do
# perform actions in the new window
end
I need to write a code for competition using STDIN and STDOUT, how can I set up eclipse to take input from STDIN??
When I was just using editor and command line I was running:
java Hatch < hatch_input
Now I need the equivalent to work directly from eclipse. It would be perfect if I could use it directly from file, but it would to suffice to just be able to paste the actual input somewhere, as long as I can write code that takes STDIN directly in eclipse by clicking RUN.
class Main{
public static void main (String[] args) throws java.lang.Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
}
}
Above code is what I am trying to achieve.
When you run your program you can setup a run configuration. Just click on on the arrow next to the play button and choose "Run configurations..."
In the new run configuration dialog you create a new Java application run configuration. In the tab "Arguments" you can enter the arguments you want the program to receive.
Suggestion: In the last tab, "common", choose to save it as a shared file, this will create a *.launch file that you can use to quickly run the program. You can also create different launch files for different inputs.
You can also just type in the input data or copy paste in the console window of the eclipse. for Sdtin when the program hits that point focus shifts to console and waits for the response.
There is following code,which i tried. this code is working fine if you run program in command prompt, but in eclipse not working because there console are no longer waiting for user input and give the java.lang.NullPointerException.
if you are read data by user input you can use System.in.read(). and this is also working in eclipse console.
In this code you can get Data from user but this data is not args which we throw at run time...
public class CONSOLE
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Console c = System.console();
System.out.println("Enter Username : \t");
String u = c.readLine();
System.out.println("Enter Password : \t");
char[] p = c.readPassword();
System.out.println("USERNAME : "+u);
System.out.println("PASSWORD : "+String.valueOf(p));
}
}
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
I included a HELP_CONTENTS action from the ActionFactory in my RCP application but I would like to open a PDF file when I call it in the application and not the normal xml file. Is that possible? I didn't find any examples online.
If you use HelpContentsAction then you'll get Eclipse help. If you want to display your own file then create your own action (you can reuse the icon and text if you want to).
Use IWorkbenchPage.openEditor(IEditorInput input, String editorId) method to open PDF file:
org.eclipse.core.resources.IFile workspaceFile;
java.io.File externalFile;
//PDF in workspace
IEditorInput input = new FileEditorInput(workspaceFile);
//or external
IFileSystem fs = org.eclipse.core.filesystem.EFS.getLocalFileSystem();
IFileStore fileStore = fs.fromLocalFile(externalFile);
input = new FileStoreEditorInput(fileStore);
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
page.openEditor(input, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);