I'm totally a newbie in terms of using Selenium ide or any automation testing tool. Now i'm stuck with this scenario: after testing elements 1 & 2 on top of the page, i need to scroll down a bit to test the elements just below 1 & 2.
I've read something about using while and endWhile commands but you have to insert user-extension.js file first. [Link: http://www.software-testing-tutorials-automation.com/2013/09/how-to-generate-mouse-scrolling-event.html]. Problem is, it doesn't work. Any help guys? Thanks much!!
you can use javascript scroll down the page :
public void javaScriptToScrollDownPage(WebDriver driver, String coordinatevalue) throws KDTKeywordExecException {
try {
((JavascriptExecutor) driver).executeScript("scroll(0, " + coordinatevalue + ")");
} catch (Exception e) {
throw new KDTKeywordExecException("Not able to scroll down the page", e);
}
}
I have created as a function, can use this. You have to change the coordinate value ie how much you want to scroll down
Similarly for scrolling up:
public void javaScriptToScrollUpPage(WebDriver driver, String coordinatevalue) throws KDTKeywordExecException {
try {
((JavascriptExecutor) driver).executeScript("scroll(" + coordinatevalue + ",0)");
} catch (Exception e) {
throw new KDTKeywordExecException("Not able to scroll up the page", e);
}
}
Related
I am not able to find the correct XPath for clicking on Logout in Facebook.
I have been trying for so long to take XPath to click on Logout.
Can anyone please help me out to click on Logout using selenium webdriver with java.
Code trials:
//clicking on navigation bar
driver.findElement(By.id("userNavigationLabel")).click();
System.out.println("Successfully clicked");
//Clicking on logout
driver.findElement(By.xpath("//span[contains(text(),'Log out')]")).click();
//closing the current tab
driver.close();
Are you getting any exception ? like NosuchElement exception or element not found error something like that.
If so, you could wait until the element is visible and then you have to perform the operation.
public void test_01_Logout()
{
WebDriver driver = new FirefoxDriver();
driver.navigate().to("www.facebook.com");
//Add login code here.
waitForElementInDOM(driver, "//div[#id='userNavigationLabel' and
contains(text(),'Account Settings')]", 15);
driver.findElement(By.xpath("//div[#id='userNavigationLabel' and
contains(text(),'Account Settings')]")).click();
waitForElementInDOM(driver, "//span[#class='54nh' and contains(text(),'Log Out')]",
15);
driver.findElement(By.xpath("//span[#class='54nh' and contains(text(),'Log
Out')]")).click();
}
-------------------------------------------------------------------------------------
public void waitForElementInDOM(WebDriver driver,String elementIdentifier, long
timeOutInSeconds)
{
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds );
try
{
//this will wait for element to be visible for 15 seconds
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath
(elementIdentifier)));
}
catch(NoSuchElementException e)
{
e.printStackTrace();
}
}
To click on the element with text as Logout you need to use WebDriverWait for the element to be clickable and you can use the following lines of code:
driver.findElement(By.cssSelector("div#userNavigationLabel")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[contains(#data-gt, 'menu_logout')]/span/span[normalize-space()='Log Out']"))).click();
I need to display multiple images dynamically, Please help me which control I have to use for this, and how to bind the images dnamically
You can use Picture Box control. for displaying Images dynamically you can write the following code in code behind
public Image GetImageObject(string imagename)
{
try
{
string _imagepath = D:\reports\Source\xyz\Images\+ imagename;
if (File.Exists( _imagepath)
{
return System.Drawing.Image.FromFile(_imagepath);
}
else
{
return null;
}
}
catch (Exception ex)
{
throw ex;
}
}
and then just create a object to your report, for Example your report Name is rptExample, suppose from BLL method,
rptExample orptExample=new rptExample();
orptExample.Logo=GetImageObject("Example.png");
orptExample.Run();
Hope this helps you.
I am trying to open a marker, while double-clicking on an entry from a TableViewer, inside an eclipse plug-in. I am able to get the associated resource from the marker, however nothing is happening while the openEditor method is executed.
The code is as below:
viewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
try {
IStructuredSelection sel = (IStructuredSelection) event.getSelection();
ReviewIssue reviewIssue = (ReviewIssue) sel.getFirstElement();
if(reviewIssue != null){
MessageDialog.openError(window.getShell(), "Insta Review", reviewIssue.getMarker().getResource());
try {
IDE.openEditor(window.getActivePage(), reviewIssue.getMarker(), true);
} catch (PartInitException e) {
MessageDialog.openError(window.getShell(), "Insta Review", e.getMessage());
}
}
} catch (Exception e) {
MessageDialog.openError(window.getShell(), "Insta Review", e.getMessage());
}
}
});
Please let me know, if am missing something here. Thanks in advance.
Also ignore the message dialogs, as I plan to implement the logging functionality later.
UPDATE:
Even though I created the marker on IFile, I was getting the same behaviour. I was finally able to open the editor by using the IFile, instead of the marker.
IFile iFile = markerProject.getFile(path);
//IMarker marker = iFile.createMarker("id.myMarker");
.....
IDE.openEditor(window.getActivePage(), reviewIssue.getiFile(), true);
//IDE.openEditor(window.getActivePage(), reviewIssue.getMarker()), true);
For this to work the IMarker.getResource() method must return an IFile. The code in IDE.openEditor is:
// get the marker resource file
if (!(marker.getResource() instanceof IFile)) {
IDEWorkbenchPlugin
.log("Open editor on marker failed; marker resource not an IFile"); //$NON-NLS-1$
return null;
}
so look in the .log file in the workspace .metadata directory to see if you are getting that log message.
Normally you would create a marker for a file using the IFile.createMarker method (createMarker is actually an IResource method).
I just trying to add add the Facebook integration with my app in Xamarin.Android. For that I found that there is a Component named as Xamarin.Social then I am trying that. Here is my attempt.
Attempt :-
void btnShare_Click(object sender, EventArgs e)
{
try
{
var facebook = new Xamarin.Social.Services.FacebookService()
{
ClientId = AppId,
RedirectUrl = new System.Uri("http://www.facebook.com/connect/login_success.html")
};
// 2. Create an item to share
var item = new Item { Text = "Xamarin.Social is the bomb.com." };
var shareController = facebook.GetShareUI(this, item, result =>
{
if (result.HasFlag(Xamarin.Social.ShareResult.Done))
{
Toast.MakeText(this, "Posted", ToastLength.Long).Show();
}
if (result.HasFlag(Xamarin.Social.ShareResult.Cancelled))
{
Toast.MakeText(this, "Cancelled", ToastLength.Long).Show();
}
});
StartActivity(shareController);
}
catch (Exception exp)
{
}
}
Note :- Facebook login page is opening successfully.
Error :- But I am getting this Forbidded(403) error. the point is this error is not reaching to catch block , but it is shown in a toast notification. so no further details are available.
Does anybody explored this component successfully ?
Any help is appreciated :)
As I mentioned in the comments, I had to many issues using the social plugin, I just used the android share intent, see example below
var shareIntent = new Intent();
shareIntent.SetAction(Intent.ActionSend);
shareIntent.PutExtra(Intent.ExtraText, message); //message is the text you want to share
shareIntent.SetType("text/plain");
StartActivity(shareIntent);
I have developed an application using net bean,
1) I'm making project in java API 6. I'm using "Net Beans 7.1".
2) I want to use JInternalFrame in my project
3) I made another package and made "JInternalFrame" there. And then call it in my main application window by firing action performed event on "JMenuItem".
4) It works fine but only one problem occurs that is, if i click on "JMenuItem" again and again, new "JInternalFrame" of same instance are opening, How can i stop that?
5) I want that, if I open "JInternalFrame" once and then i again click on "JMenuItem" to open the same "JInternalFrame", it Should do nothing or it shows the window which already opened and minimized
sample code:
<code>
private void empDataActionPerformed(java.awt.event.ActionEvent evt) {
Emps employees = new Emps();
desktop.add(employees);
employees.setVisible(true);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
employees.setBounds(230, 40, screenSize.width / 2 - 80, screenSize.height / 2 + 105);
}
<code>
please I need help.
Here is may sample code. hope this help.
Menu action to call internal frame in main application where JdesktopPane in it.
private void YourJinternalFrameMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
YourJinternalFrame nw = YourJinternalFrame.getInstance();
nw.pack();
//usefull part for you.. if open shows, if not creates new one
if (nw.isVisible()) {
} else {
desktopPane.add(nw);
nw.setVisible(true);
}
try {
nw.setMaximum(true);
} catch (PropertyVetoException ex) {
Logger.getLogger(MainApplication.class.getName()).log(Level.SEVERE, null, ex);
}
}
put this inside of your YourJinternalFrame
private static YourJinternalFrame myInstance;
public static YourJinternalFrame getInstance() {
if (myInstance == null) {
myInstance = new YourJinternalFrame();
}
return myInstance;