2

How To Write Code in Selenium To Click This Picture , Down I Have Attached My Selenium Code.

package Login;

import java.io.File;
import java.io.IOException;

import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;

public class Signup {
    WebDriver driver;
     @BeforeMethod
      public void beforeMethod() 
      {
          System.setProperty("webdriver.chrome.driver", "F:\\New folder\\chromedriver.exe");
           driver = new ChromeDriver();
           driver.get("http://xxx.xx.xx.xx:xxxx/index");
      }
  @Test
  public void f() 
  {
      driver.findElement(By.xpath("//a[@class='login-option'][contains(text(),'Login')]")).click();

      driver.findElement(By.xpath("//button[@id='callsignup']")).click();
  }

  @AfterMethod
  public void afterMethod() throws EncryptedDocumentException, InvalidFormatException, IOException 
  {
      String un = Signup.Getdata(1, 0);

      driver.findElement(By.id("Name-new")).sendKeys(un);

      String em= Signup.Getdata(1, 1);

      driver.findElement(By.id("emailids")).sendKeys(em);

      String ps = Signup.Getdata(1, 2);

      driver.findElement(By.id("pswids")).sendKeys(ps);

      String pho = Signup.Getdata(1, 3);

      driver.findElement(By.id("phoneNo")).sendKeys(pho);

      String age = Signup.Getdata(1, 4);

      driver.findElement(By.id("age-new")).sendKeys(age);

      String city = Signup.Getdata(1, 5);

      driver.findElement(By.id("city-new")).sendKeys(city);

      driver.findElement(By.xpath("//input[@id='menrd']")).click();
     try
     {
     WebElement e1 = driver.findElement(By.xpath("/html[1]/body[1]/div[2]/div[3]/div[1]/ss-auth-form[1]/md-card[1]/ss-signup-form[1]/div[1]/form[1]/div[6]"));
     Actions a1 = new Actions(driver);
     a1.moveToElement(e1).click(e1).build().perform();
     }
     catch(Exception e)
     {
         System.out.println("The Button can't Be Clicked!!");
     }
     // driver.findElement(By.xpath("//ss-submit-button[@label='Sign Up']//input[@class='submit']")).click();

  }

  public static String Getdata(int r, int c) throws EncryptedDocumentException, InvalidFormatException, IOException
  {
      File targetfile = new File("F:\\Test","Book2.xlsx");  

      Workbook wb = WorkbookFactory.create(targetfile);

        String s1 = wb.getSheet("Test1").getRow(r).getCell(c).getStringCellValue();


        return s1;

  }
}

Image Reference

  • checkout here sqa.stackexchange.com/questions/17022/… you will get some idea – Kannathasan Jun 18 '18 at 9:48
  • @koushick you may want to remove the IP address and port of your testing website from Stack Exchange – Aaron F Jun 18 '18 at 14:14
  • @AaronF What are You Trying To Say, Can't Get it Man? – koushick Jun 20 '18 at 6:45
  • @AaronF Yay! Man i Get it. You are Saying About My Testing Ip Adress. Okay Fine Man. Thanks. – koushick Jun 20 '18 at 6:47
7

There is not any way to automate captcha submission. Actually, that's the reason captcha is used for. All you can do are:

  • ReCAPTCHA's documentation provides a set of keys that you can use for testing. You can also whitelist your testing domains for exclusion.

  • Run your tests on a development or staging environment and disable the CAPTCHA in that environment.

  • In your test, submit the form without submitting the CAPTCHA and then check for the CAPTCHA error. Expectedly you won't be able to successfully submit the form this way, but you'll be able to test whether it's validating properly or not.

| improve this answer | |
1

Selenium can't handle CAPTCHA.

CAPTCHA, an acronym for "Completely Automated Turing Test to tell Computers and Humans Apart". It is to determine whether or not the user is a human. If you can simply automate a Captcha using Selenium, then the main purpose of Captcha becomes useless.

Reference:

  1. How-to-handle-captcha-using-selenium-web-driver
| improve this answer | |
0

You can bypass ReCAPTCHA, but you won't be testing the box itself - this basically enables you to switch it off in your test environment.

Check out Google Developer's FAQ page here:

I'd like to run automated tests with reCAPTCHA v2. What should I do?

With the following test keys, you will always get No CAPTCHA and all verification requests will pass.

Site key: 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI

Secret key: 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.