getting no such element exception - css

i am getting error as element cannot be found when executing code for one of the test application. I have written code to locate element using css and xpath,but still getting same issue. can any one help?
code :
public static WebDriver driver;
public static void setUp() {
System.setProperty("webdriver.ie.driver", "Resources\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
//System.setProperty("webdriver.gecko.driver", "D:\\selenium\\geckodriver\\geckodriver.exe");
driver.get("http://demo.actitime.com/");
driver.manage().window().maximize();
driver.findElement(By.id("username")).sendKeys("user");
driver.findElement(By.name("pwd")).sendKeys("user");
driver.findElement(By.cssSelector("#loginButton > div")).click();
//Wait<WebDriver> wait=new WebDriverWait(driver, 30);
//wait.until(ExpectedConditions.presenceOfElementLocated(By.id("logoutLink")));
//String parentWindow= driver.getWindowHandle();
driver.findElement(By.cssSelector("div.popup_menu_icon.support_icon > div.popup_menu_arrow")).click();
//driver.findElement(By.xpath("id('topnav')/x:tbody/x:tr[1]/x:td[5]/x:table/x:tbody/x:tr/x:td[2]/x:div/x:table/x:tbody/x:tr[2]/x:td/x:div/x:div[2]/x:div/x:div[1]/x:div[2]")).click();
driver.findElement(By.linkText("User Guide")).click();
}
public static void tearDown() {
driver.quit();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
setUp();
tearDown();
}
}

When you click on the Login Button it takes the browser a couple of seconds to send your request and return/render the response page, But in your code, You're trying to click the Help button right after clicking the login button(the help button isn't displayed yet), Which won't find the element you're looking for in the current page, because you're still on the login page.
So you need to wait till the page after the login is rendered and then you can select and click on whatever you want.
To wait for the element to be clickable use this code:
WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(cssSelector("div.popup_menu_icon.support_icon > div.popup_menu_arrow")));
EDIT:
It seems that you're using the wrong css selector. Try this one:
cssSelector("div.popup_menu_button.popup_menu_button_support")

Related

Error in JavaFX WebView listener for click event while trying to record that a click has been performed on a page

The primary purpose is to Print "click operation has been performed" in the console, if any click is performed on the page loaded in the embedded browser, for achieving the aforementioned behavior I got the below code, it shows error.
((EventTarget) el).addEventListener("click", listener, false);
Here is the complete code snippet:
https://docs.oracle.com/javafx/2/api/javafx/scene/web/WebEngine.html
EventListener listener = new EventListener() {
public void handleEvent(Event ev) {
System.out.println("Click Operation has been performed");
}
};
Document doc = webEngine.getDocument();
Element el = doc.getElementById("dummyid");
((EventTarget) el).addEventListener("click", listener, false);
As shown in the link you've provided, you can call java methods by using JSObject.setMember method.
public class JavaApplication {
public void exit() {
Platform.exit();
}
}
...
JSObject window = (JSObject) webEngine.executeScript("window");
window.setMember("app", new JavaApplication());
You can call from the web page
Click here to exit application
This could be an alternative solution instead of using handlers

Calling a non-parental Activity method from fragment without creating a new instance

I have my MainActivity and inside that I have a number of fragments. I also have another activity that works as my launcher and does everything to do with the Google Drive section of my app. On start up this activity launches, connects to Drive and then launches the MainActivity. I have a button in one of my fragments that, when pushed, needs to call a method in the DriveActivity. I can't create a new instance of DriveActivity because then googleApiClient will be null. Is this possible and how would I go about doing it? I've already tried using getActivity and casting but I'm assuming that isn't working because DriveActivity isn't the fragments parent.
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//TODO for test only remove
directory = new Directory(SDCARD + LOCAL_STORAGE);
byte[] zippedFile = directory.getZippedFile(SDCARD + STORAGE_LOCATION + directory.getZipFileName());
//Here I need to somehow call DriveActivity.uploadFileToDrive(zippedFile);
//((DriveActivity)getActivity()).uploadFileToDrive(zippedFile);
}
});
Right, so I'm having a bit of difficulty with the heirarchy but I think what you want to do is define a method in the fragment that the activity will be required to override to use.
This will allow you to press the button, and then fire a method whos actual implementation is inside the parent.
public interface Callbacks {
/**
* Callback for when an item has been selected.
*/
public void onItemSelected(String id);
}
example implementation:
private static Callbacks sDummyCallbacks = new Callbacks() {
#Override
public void onItemSelected(String id) {
//Button fired logic
}
};
so in the child you'd do just call:
this.onItemSelected("ID of Class");
EDITED
In retrospect what I believe you need is an activity whos sole purpose is to upload files, not fire off other activities.
Heres an example of a 'create file' activity:Google Demo for creating a file on drive
Heres an example of the 'base upload' activity' Base Service creator

How to specify a button to open an URL?

I want to write a web application that triggers the default email client of the user to send an email.
Thus, I created a Link, that leads to an URL conforming to the mailto URI scheme (http://en.wikipedia.org/wiki/Mailto):
Link emailLink = new Link("Send Email",
new ExternalResource("mailto:someone#example.com"));
However, instead of using a Link, I want to provide a Button that allows to trigger the respective functionality. But, for buttons I cannot set an ExternalResource to be opened.
Does anybody know to solve this problem for Buttons, or how to create a Link that looks and behaves exactly like a button? I also tried some CCS modification but did not manage the task by myself. I also found some solutions for former Vaadin versions (https://vaadin.com/forum/#!/thread/69989), but, unfortunately they do not work for Vaadin 7.
I remember solving a similar problem using a ResourceReference.
Button emailButton = new Button("Email");
content.addComponent(emailButton);
Resource res = new ExternalResource("mailto:someone#example.com");
final ResourceReference rr = ResourceReference.create(res, content, "email");
emailButton.addClickListener(new Button.ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
Page.getCurrent().open(rr.getURL(), null);
}
});
For solving similar issue, I applied previously:
String email="info#ORGNAME.org";
Link l=new Link();
l.setResource(new ExternalResource("mailto:" + email));
l.setCaption("Send email to " + email);
addComponent(l);
After some further tries a managed to adapt the proposed LinkButton solution from https://vaadin.com/forum/#!/thread/69989 for Vaadin 7:
public class LinkButton extends Button {
public LinkButton(final String url, String caption) {
super(caption);
setImmediate(true);
addClickListener(new Button.ClickListener() {
private static final long serialVersionUID = -2607584137357484607L;
#Override
public void buttonClick(ClickEvent event) {
LinkButton.this.getUI().getPage().open(url, "_blank");
}
});
}
}
However, this solution is still not perfect as it causes the opening of a popup window being blocked by some web browsers.

Windows Form TopMost don't work with BackgroundWorker?

I'm trying to show window when user need to be notify about some work to do. Every think work fine, but i want to show form absolute topmost. I set form property TopMost = true but it does not work, window still show behind other forms.
I figure out that TopMost = true don't work only with BackgroundWorker, when i use Timer class it work fine. I'm wonder why? Anybody can explain me this?
Here is simple example what i want to do.
static void Main(string[] args)
{
try
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerAsync();
Application.Run(new Form());
}
catch (Exception exp)
{
Console.WriteLine(exp);
}
}
static void worker_DoWork(object sender, DoWorkEventArgs e)
{
while (true)
{
System.Threading.Thread.Sleep(1000);
if (NeedNotify())
{
NotifyForm myNotifyForm = new NotifyForm();
myNotifyForm.TopMost = true;
myNotifyForm.ShowDialog(); // NotifyForm still show behind others windows
}
}
}
private static bool NeedNotify()
{
return true;
}
}
Creating the form within the background worker causes the form to be created on a different thread. Instead, create and show the form in your main thread before calling RunWorkerAsync.
Another problem may arise from the fact that you're creating the "notification" before the application's main loop is even started. You may consider reorganizing your code so that the background worker is started from the main form's OnLoad event.

asp.net watin: error occur while performing testing using watin in asp.net?

I have used the below code for testing the JavaScript simple validation.
And below is the code I have used for WatiN.
[STAThread]
static void Main(string[] args)
{
IE ie = new IE("http://localhost:2034/WebForm3.aspx");
ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Maximize);
var confirm = new ConfirmDialogHandler();
ie.AddDialogHandler(confirm);
ie.TextField("TextBox1").TypeText("Pa");
ie.Button("Button2").ClickNoWait();
//dialoghandler.WaitUntilExists(5);
confirm.OKButton.Click();
var dialoghandler = new AlertDialogHandler();
ie.AddDialogHandler(confirm);
**dialoghandler.OKButton.Click();**//the error is could not find dialog does not exist.
dialoghandler.WaitUntilExists(10);
}
For errors in Dialogbox OK click, you can resolve by...
ConfirmDialogHandler handler = new ConfirmDialogHandler();
using (new UseDialogOnce(ie.DialogWatcher, handler))
{
//trigger the event to popup dialogbox
ie.Button("Button2").ClickNoWait(); //Copied from your code
handler.WaitUntilExists();
handler.OKButton.Click();
}

Resources