Showing posts with label selenium. Show all posts
Showing posts with label selenium. Show all posts

Element is not clickable at point using chrome driver

When you are trying to click on a element using chrome driver you may come across the error element is not clickable at this point.

This is due to the chrome driver always clicks the middle of the element in attempt to be faithful to what an actual user does.

The chrome driver first identifies the location of the element then clicks the middle of the element.

So if you are trying to click on a moving element, the chrome driver tries to clicks at the position where it first finds that element. And at the time of clicking , if the element is not at the same position, then chrome driver throws the error "Element is not clickable at this position". 

You may get this error in the following cases.

1. If the position of the element is changing in the DOM. 
2. If you are applying transformations/transitions/animations to that element.
3. If you are trying to click on a element before it gets loaded etc.

You don't face any problem when you are testing in IE or FF. You mostly face this issue when you are testing on chrome.

Quick Fix for Element is not clickable at point:


After reading all the discussions in the webdriver community at this page  https://code.google.com/p/selenium/issues/detail?id=2766 , i have found some quick fixes with which you can solve this issue

1. Many people are facing this issue only after upgrading to newer version of Chrome Driver
In the older version we have implicit waits, which waits for the element to be fully loaded. But now we have to explicitly wait for the element to load. 

We can do this by telling the browser to sleep for some time (say 2 seconds).

We have the following commands to tell the browser to sleep for some 'x' seconds  (choose the command based on your testing tool)

browser.sleep(2000); // for angular e2e testing using protractor
Thread.Sleep(2000); // for selenium webdriver

2. I see one more work around in the comment 27 in the above page

Scroll the element into view before clicking it.

For Javascript with webdriver:

IWebElement element = driver.findElement(By.xpath('element xpath'));
(driver as IJavaScriptExecutor).ExecuteScript(string.Format("window.scrollTo(0,{0});",element.Location.Y));
element.Click();

You cal also try following code

WebElement element = driver.findElement(By.xpath('element xpath'));
((JavaScriptExecutor) driver).ExecuteScript("window.scrollTo(0,"+element.getLocation().y+")");
element.click();

For Python:

ActionChains(w).move_to_element_with_offset(link,0,20).click().perform();

For Ruby with Capybara and selenium web-driver

#where @session is Capybara::session instance
#and object is a Capybara::Node::Element istance
@session.driver.execute_script "window.scrollTo(#{object.native.location.x},#{object.native.location.y})"
return_string = object.native.click 

Using the above work arounds you can solve the issue "Element is not clickable at point"
Read more...

The type or namespace name 'NUnit' could not be found

If you are new to selenium rc/ selenium webdriver and when you run your code you may see these types of errors

The type or namespace name 'NUnit' could not be found.

The type or namespace name 'TestFixture' could not be found

The type or namespace name 'ISelenium' could not be found

The type or namespace name 'SetUpAttribute' could not be found

If you are getting the above errors, It means you have not added required dll's to your project.

So add the following dll's to your project

nmock.dll
nunit.core.dll
nunit. framework.dll
ThoughtWorks.Selenium.Core.dll
ThoughtWorks.Selenium.IntegrationTests.dll and
ThoughtWorks.Selenium.UnitTests.dll

To add the above dll's --> right click on reference in the solution explorer and select add reference and browse for the required dll.

The NUNIT dll's can be downloaded from the NUNIT website. http://www.nunit.org/index.php?p=download

And the dll's related to selenium can be downloaded from http://docs.seleniumhq.org/download/


Hope this post helps you.

For more posts related to selenium rc/selenium Webdriver See this : Selenium RC/ Selenium Webdriver


Read more...

Press Enter Key in Selenium

If you are working with a SearchBox using Selenium. In which you have to type something and you have to press Enter to search. You can do it in the following way...


// this sends an Enter to the element

selenium.type("locator", Keys.ENTER);


// The below code sends the "Any text" and then confirms it with Enter

selenium.type("locator", "Any text" + Keys.ENTER);


Here locator means You have to add the TextBox's Id.  

or try this


selenium.KeyPressNative("13");

or


selenium.keyDown("locator of element", "\\13");

Where 13 is the ASCII value of Enter Key.. 

Hope this may help you.
Read more...

Sending email with attachments from C#


In many cases you may required to send emails using ASP.NET. You can have all the classes required to send an email in the System.Net.Mail namespace. You can send an email from ASP.NET as follows :

First you have to add these namespaces to your code behind file:

1. using System.Net;
2. using System.Net.Mail;

Then write the following method

public void email_send()
{
    MailMessage mail = new MailMessage();
    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
    mail.From = new MailAddress("your [email protected]");
    mail.To.Add("[email protected]");
    mail.Subject = "Test Mail - 1";
    mail.Body = "mail with attachment";

    System.Net.Mail.Attachment attachment;
    attachment = new System.Net.Mail.Attachment("c:/textfile.txt");
    mail.Attachments.Add(attachment);

    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("your [email protected]", "your password");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mail);

}

Using the above you can send attachemebts also. Hope this helps :-)
Read more...

No connection could be made because the target machine actively refused it 127.0.0.1:4444

I had this issue and it took a lot of time to find the solution for this. I searched many sites for the solutions. After few hours, i have found the solution for this issue. (This is the solution which worked for me . I hope this will work for others also.)

The problem is i din't start the selenium server. After starting the server, issue gone and all worked fine.

You can download selenium server here. Download Selenium server

After downloading start the selenium server. See screen shot below


Read more...