Selenium | Anagha | 7th Sept

Discussion in 'Web App and Programming' started by Shalini Rana, Sep 6, 2019.

  1. Shalini Rana

    Shalini Rana Well-Known Member
    Simplilearn Support

    Joined:
    Jul 24, 2017
    Messages:
    325
    Likes Received:
    21
    Hi All!

    Please share your queries here for any assistance required during your training journey.

    Thanks!
     
    #1
    Chanchala Gorale likes this.
  2. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    Hello Learners,

    Welcome to Selenium Batch,

    Please download these installers from this drive location :
    https://drive.google.com/open?id=1pvqFW8B48qwkDI-nlYh2O-LxJzq7eE8i
    Create a folder called Installers and keep all this downloaded file in that location.

    And Please install Java 8 on your systems..
    If you have later version of java, please uninstall that and install Java 8.
     
    #2
    Rajashekar Bardipuram likes this.
  3. Rupali_14

    Rupali_14 Member

    Joined:
    Jun 28, 2017
    Messages:
    9
    Likes Received:
    1
    Hi Anagha,

    I have a query with the assignment given. I have created the different methods for add, subtract and multiply and also to display name but when I call display at the top in main, it works fine but when I call display after the add, multiply and subtract methods, display method does not work.

    Thanks
    Rupali
     
    #3
  4. Jayashri Gurunathan

    Joined:
    Aug 8, 2019
    Messages:
    2
    Likes Received:
    1
    Assignment:
    package com.shri.intro;



    import java.util.Scanner;



    public class Operations {



    publicint add(intnum1, intnum2) {

    intresult = num1 + num2;

    return (result);



    }



    publicint sub(intnum1, intnum2) {

    intresult = num1 - num2;

    return (result);



    }



    publicint mul(intnum1, intnum2) {

    intresult = num1 * num2;

    return (result);



    }



    publicint div(intnum1, intnum2) {

    intresult = num1 / num2;

    return (result);



    }



    public static void main(String[] args) {

    // TODO Auto-generated method stub



    Scanner inp_obj = new Scanner(System.in);

    Operations op = new Operations();



    intFirstNum;

    intSecNum;



    System.out.println("Enter the First number:");

    FirstNum = inp_obj.nextInt();



    System.out.println("Enter the Second number:");

    SecNum = inp_obj.nextInt();



    System.out.println("The Sum is:" + op.add(FirstNum, SecNum));

    System.out.println("The Sub is:" + op.sub(FirstNum, SecNum));

    System.out.println("The mul is:" + op.mul(FirstNum, SecNum));

    System.out.println("The Div is:" + op.div(FirstNum, SecNum));



    inp_obj.close();

    }



    }
     
    #4
    Anagha Gadgil likes this.
  5. Neena Gupta

    Neena Gupta Member

    Joined:
    Feb 20, 2019
    Messages:
    9
    Likes Received:
    4
    Hi Anagha. please see today's assignment


    package com.simplilearnfolder.day1and2;

    import java.util.Scanner;

    public class PerformFunctions {

    //Perform Add function for two integers
    public static int add(int x, int y) {
    return x + y;
    }

    // Perform Subtract function for two integers
    public static int sub(int x, int y) {
    return x - y;
    }

    // Perform Multiply function for two integers
    public static int mult(int x, int y) {
    return x * y;
    }

    public static void main(String[] args) {

    // To get inputs from the user using scanner class

    Scanner inputobj = new Scanner(System.in);

    System.out.print("Enter name: ");
    String name = inputobj.nextLine();

    System.out.print("Enter first integer: ");
    int a = inputobj.nextInt();

    System.out.print("Enter second integer: ");
    int b = inputobj.nextInt();

    System.out.println(a + " + " + b + " = " + add(a, b));
    System.out.println(a + " - " + b + " = " + sub(a, b));
    System.out.println(a + " x " + b + " = " + mult(a, b));

    System.out.println("Name: " + name);

    }
    }
     
    #5
    Anagha Gadgil likes this.
  6. Motilal Biswal

    Joined:
    Jul 29, 2019
    Messages:
    4
    Likes Received:
    3
    Hi Anagha,
    Please find the below assignement.

    import java.util.Scanner;
    public class Assignment1 {

    public int add(int i, int j) {
    int c=i+j;
    return c;
    }
    public int substract(int i, int j) {
    int c=i-j;
    return c;
    }
    public int multiply(int i, int j) {
    int c=i*j;
    return c;
    }
    public static void main(String[] args) {
    Scanner sc1=new Scanner(System.in);
    System.out.print("Enter your Name: ");
    String s=sc1.nextLine();
    System.out.print("Enter 1st number: ");
    int num1=sc1.nextInt();
    System.out.print("Enter 2nd number: ");
    int num2=sc1.nextInt();
    System.out.println();
    sc1.close();
    System.out.println("Name: "+s);
    Assignment1 a=new Assignment1();
    int sum=a.add(num1, num2);
    System.out.println("Addition: "+sum);
    int sub=a.substract(num1, num2);
    System.out.println("Substraction: "+sub);
    int multi=a.multiply(num1, num2);
    System.out.println("Multiplication: "+multi);

    }
    }
     
    #6
    Anagha Gadgil likes this.
  7. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    Send me the code.
     
    #7
  8. Rupali_14

    Rupali_14 Member

    Joined:
    Jun 28, 2017
    Messages:
    9
    Likes Received:
    1
    /*Assignment :

    Write a program to accept 2 numbers from user, perform function : add, subtract and

    multiple. Print the results…. Use different methods for each function..

    Call these methods from main.

    Also accept your name as input and print it.*/

    package JavaPract;

    import java.util.Scanner;

    public class Assignment_selenium {
    public static int a, b;

    public static String name;

    public static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {

    display();
    System.out.print("Please enter first number: ");

    a = scan.nextInt();

    System.out.print("Please enter second number: ");

    b= scan.nextInt();

    add();

    subtract();

    multiply();

    scan.close();


    }

    publicstaticvoid add()

    {

    int add = a+b;

    System.out.println("The result of addition is: "+add);

    }


    publicstaticvoid subtract()

    {

    int subtract = a-b;

    System.out.println("The result of subtraction is: "+subtract);

    }


    public static void multiply()

    {

    int multiply= a*b;

    System.out.println("The result of multiplications is: "+multiply);

    }


    publicstaticvoid display()

    {

    System.out.print("Please enter the name: ");

    name = scan.nextLine();

    System.out.println("The name is: " +name);

    }

    }

    In the code above, it is working fine as I call display function on the top in the main function the name ,
    but if I write display function below the multiply function as in the code below, it doesn't let me input the value in the console from the user.


    package JavaPract;

    import java.util.Scanner;

    public class Assignment_selenium {
    public static int a, b;

    public static String name;

    public static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {

    System.out.print("Please enter first number: ");

    a = scan.nextInt();

    System.out.print("Please enter second number: ");

    b= scan.nextInt();

    add();

    subtract();

    multiply();

    display();

    scan.close();


    }

    publicstaticvoid add()

    {

    int add = a+b;

    System.out.println("The result of addition is: "+add);

    }


    publicstaticvoid subtract()

    {

    int subtract = a-b;

    System.out.println("The result of subtraction is: "+subtract);

    }


    public static void multiply()

    {

    int multiply= a*b;

    System.out.println("The result of multiplications is: "+multiply);

    }


    publicstaticvoid display()

    {

    System.out.print("Please enter the name: ");

    name = scan.nextLine();

    System.out.println("The name is: " +name);

    }

    }
     
    #8
    Last edited: Sep 8, 2019
  9. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20

    Add this line beforeSystem.out.print("Please enter the name: ");

    inputobj.nextLine(); // This skips the newline character . reqd when nextInt is used before this
     
    #9
  10. Subhash Deshwal

    Subhash Deshwal Customer
    Customer

    Joined:
    Sep 6, 2019
    Messages:
    1
    Likes Received:
    1
    Hi Anagha,
    Please find below given assignment:


    package simplilearn.practice;
    import java.util.Scanner;

    public class ArithmeticOperation {

    //main function
    public static void main(String args[])
    {
    Scanner inputObj = new Scanner(System.in);
    ArithmeticOperation obj = new ArithmeticOperation();
    System.out.println("Enter your name: ");
    String name = inputObj.nextLine();


    System.out.println("Enter First integer Number: ");
    int num1 = inputObj.nextInt();
    System.out.println("Enter Second integer Number: ");
    int num2 = inputObj.nextInt();

    System.out.println("My name is : " +name);
    System.out.println("Addition of two numbers : " +obj.addition(num1, num2));
    System.out.println("Subtraction of two numbers : " +obj.subtraction(num1, num2));
    System.out.println("Multiplication of two numbers : "+obj.multiplication(num1, num2));
    }
    /*
    * function for adding two integers
    */
    public int addition(int num1, int num2)
    {
    return num1 + num2;
    }
    /*
    * function for Subtracting two integers
    */
    public int subtraction(int num1, int num2)
    {
    if (num1 >= num2){
    return num1 - num2;
    }
    else {
    return num2-num1;
    }

    }
    /*
    * function for multiplying two integers
    */
    public int multiplication(int num1, int num2)
    {
    return num1 * num2;
    }

    }
     
    #10
    Anagha Gadgil likes this.
  11. Jayashri Gurunathan

    Joined:
    Aug 8, 2019
    Messages:
    2
    Likes Received:
    1

    Hi,
    If I try to read a string using Scannerobject.nextLine() at the end of the code it's not working but if the same method was in the begining it was working.
    For exxample: the below code is not working:
    package com.shri.intro;
    import java.util.Scanner;
    public class AddNumbers {
    public static void main(String args[]) {
    intnum1, num2, result;

    // String str = "Addition";

    Scanner input = new Scanner(System.in);



    System.out.println("Enter the First number:");

    num1 = input.nextInt();



    System.out.println(" Enter the Second number:");

    num2 = input.nextInt();



    result = num1 + num2;

    System.out.println("The result is:" + result);



    System.out.println(" Enter the text:");

    String str = input.nextLine();




    // System.out.println("I got:"+str);

    input.close();
    }

    }

    But, if the red marked lines are before getting the first number then it works.
     
    #11
  12. Chandrika S Naidu

    Joined:
    Mar 18, 2019
    Messages:
    4
    Likes Received:
    1
     
    #12
  13. Chandrika S Naidu

    Joined:
    Mar 18, 2019
    Messages:
    4
    Likes Received:
    1
    Hi Anagha,
    I tried downlaoding the installer link for eclipse installation. The download is not working. other downloads are working. so I am trying to download directly from the eclipse website https://www.eclipse.org/downloads/packages/release.
    As there are many releases and many packages within each release, please give me the exact version and package of eclipse. If you can give me the eclipse website url, that will be great.

    Thanks,
    Chandrika
     
    #13
  14. Rupali_14

    Rupali_14 Member

    Joined:
    Jun 28, 2017
    Messages:
    9
    Likes Received:
    1
    Hi Anagha,

    Thanks for your reply. Now I have resolved my problem by using 2 scanner classes and used the second scanner for my nextLine method.
    /*Assignment :

    Write a program to accept 2 numbers from user, perform function : add, subtract and

    multiple. Print the results…. Use different methods for each function..

    Call these methods from main.

    Also accept your name as input and print it.*/

    package JavaPract;

    import java.util.Scanner;

    public class Assignment_selenium {

    public static int a, b;

    public static String name;

    public static Scanner scan = new Scanner(System.in);

    public static Scanner scan2 = new Scanner(System.in);

    public static void main(String[] args) {

    System.out.print("Please enter first number: ");

    a = scan.nextInt();

    System.out.print("Please enter second number: ");

    b= scan.nextInt();

    //scan.nextLine();

    add();

    subtract();

    multiply();

    display();

    scan.close();

    scan2.close();
    }
    publicstaticvoid add()
    {

    int add = a+b;

    System.out.println("The result of addition is: "+add);

    }

    publicstaticvoid subtract()

    {

    int subtract = a-b;

    System.out.println("The result of subtraction is: "+subtract);

    }

    public static void multiply()

    {

    int multiply= a*b;

    System.out.println("The result of multiplications is: "+multiply);

    }

    publicstaticvoid display()
    {

    System.out.print("Please enter the name: ");

    name= scan2.nextLine();

    System.out.println("The name is: " +name);

    }

    }
     
    #14
  15. Rupali_14

    Rupali_14 Member

    Joined:
    Jun 28, 2017
    Messages:
    9
    Likes Received:
    1
    Hi,
    I was getting same issue, so please see user input.nextLine() immediately after the nextInt() and then write Enter the text lines

    Thanks
     
    #15
  16. Chandrika S Naidu

    Joined:
    Mar 18, 2019
    Messages:
    4
    Likes Received:
    1
    I have installed the eclipse version below ecLipse 2018-12 M1 package for java developers

    Eclipse DSL Tools
    Version: 2018-12 M1 (4.10.0)
    Build id: 20181019-0742


    hope this version is ok for our course
     
    #16
  17. Rajashekar Bardipuram

    Joined:
    Aug 6, 2019
    Messages:
    4
    Likes Received:
    0
    Hi Anagha,
    please find the given assignment

    scanner function
    ==================
    package com.JavaBasics;

    import java.util.Scanner;

    public class ScannerClass {
    int x, y;



    public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner obj1 = new Scanner(System.in);
    System.out.println("Enter the value of x :");
    int x = obj1.nextInt();

    System.out.println("Enter the value of y :");
    int y = obj1.nextInt();
    int sum=x+y;
    int mul=x*y;


    System.out.println("The sum of two numner :" + sum);
    System.out.println("The mul of two numner :" + mul);

    obj1.close();

    }

    }
    ========================================================
    using construnctor
    package com.JavaBasics;

    public class ConstructorClass {
    int x, y;
    int sum;
    float substract;
    float mul, Div;

    public void add(int x, int y) {
    this.x=x;
    this.y=y;
    sum = x + y;
    }

    public void substract(int x, int y) {
    this.x=x;
    this.y=y;
    substract = x - y;

    }

    public void Mul(int x,int y) {
    this.x=x;
    this.y=y;
    mul = x * y;
    }

    public void Div(int x ,int y) {
    this.x=x;
    this.y=y;
    Div = x / y;
    }

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    ConstructorClass obj= new ConstructorClass();
    obj.add(10,20);
    obj.substract(100,200);
    obj.Mul(10,20);
    obj.Div(100,5);

    System.out.println("Add of two number" + obj.sum);
    System.out.println("sub of two number" + obj.substract);
    System.out.println("mul of two number" + obj.mul);
    System.out.println("div of two number" + obj.Div);
    }

    }
     
    #17
    Last edited: Sep 8, 2019
  18. chandrabadam

    chandrabadam Customer
    Customer

    Joined:
    Aug 26, 2019
    Messages:
    1
    Likes Received:
    0
    This is regarding overload the main method we discussed in today's class.....
    We can overload the main method in Java
    Example:
    public class Sample{
    public static void main(){
    System.out.println("This is the overloaded main method");
    }
    public static void main(String args[]){
    Sample obj = new Sample();
    obj.main();
    }
    }
    Output:
    This is the overloaded main method
     
    #18
  19. Neena Gupta

    Neena Gupta Member

    Joined:
    Feb 20, 2019
    Messages:
    9
    Likes Received:
    4
    Hi Anagha,

    I was able to execute in firefox and close in the end. but still saw a couple of red messages. I had also copied the chrome webdriver. Please let me know if i need to do something.
    Thanks,
    Neena

    The tile of the page is : Selenium - Web Browser Automation
    https://www.seleniumhq.org/
    1567965429076 Marionette INFO Stopped listening on port 52092
    [Parent 11040, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566864336/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
    [Child 20172, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566864336/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
    [Child 20172, Chrome_ChildThread] WARNING: pipe error: 109: file z:/ta[Parent 11040, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566864336/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
    [Parent 11040, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566864336/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
    [Child 856, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566864336/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
    [Child 856, Chrome_ChildThread] WARN[Parent 11040, Gecko_IOThread] WARNING: pipe error: 109: file z:/task_1566864336/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
    [Child 988, Chrome_ChildThread] WARNING: pipe error: 109: file z:/task_1566864336/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 341
    [Child 988, Chrome_ChildT
    ###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost

    [GPU 19188, Chr
    ###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv
     
    #19
  20. Rupali_14

    Rupali_14 Member

    Joined:
    Jun 28, 2017
    Messages:
    9
    Likes Received:
    1
    Hi Anagha,

    Can you please share yesterday notes link?

    Thanks
    Rupali
     
    #20
  21. Rajashekar Bardipuram

    Joined:
    Aug 6, 2019
    Messages:
    4
    Likes Received:
    0
    Hi Anagha,
    Please share the Day 2 notes
     
    #21
  22. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    Thanks for sharing. Is there any use case for doing this?
     
    #22
  23. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    Shared the Day 2 notes and java programs on the drive
     
    #23
  24. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    These are warnings. Nothing to be done if your Firefox is working fine
     
    #24
    Motilal Biswal likes this.
  25. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    Should work. if it doesn't then you can install IDE for java developers..
     
    #25
  26. Rajashekar Bardipuram

    Joined:
    Aug 6, 2019
    Messages:
    4
    Likes Received:
    0
    Hi Anagha,
    I just tried the sample selenium script for login ..
    Launch browser method and main class is single class file and login and closeDriver i used other class file with -out main method...
    login and closeDriver class instance object reference created in main method but when i call login method and close method inside action are not working ...could you please help me where did mistake .
    Attached three class files
     

    Attached Files:

    #26
  27. Rupali_14

    Rupali_14 Member

    Joined:
    Jun 28, 2017
    Messages:
    9
    Likes Received:
    1
    Hi Anagha,

    I am unable to find the java files in the folder on the drive. Can you please share the java files drive link here
     
    #27
  28. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    you have sent me 0bytes file. copy paste your code here.
     
    #28
  29. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    #29
  30. Rajashekar Bardipuram

    Joined:
    Aug 6, 2019
    Messages:
    4
    Likes Received:
    0
    package com.JavaBasics;

    import java.sql.Driver;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;

    public class SeleniumTest {

    public void LaunchBrowser() {

    // System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver"); //mac
    System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver.exe"); // windows
    // Which browser //Path to the driver file

    // Lauch your firefox browser
    WebDriver driver = new FirefoxDriver();

    // For chrome browser
    //System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver.exe");
    //WebDriver driver = new ChromeDriver();

    // For IE
    // System.setProperty("webdriver.ie.driver",
    // "D://SeleniumInstallers//drivers//IEDriverServer.exe");

    // For IE
    // WebDriver driver = new InternetExplorerDriver();

    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
    //driver.get("https://www.seleniumhq.org");
    driver.get("https://www.facebook.com/");

    }



    public static void main(String[] args) {

    SeleniumTest obj = new SeleniumTest();
    obj.LaunchBrowser();
    Login obj2=new Login();
    obj2.login();
    CloseDriver obj3=new CloseDriver();
    obj3.close();
    }
    }
    ===============================================================================================================================
    package com.JavaBasics;

    import org.openqa.selenium.WebDriver;

    public class Login {
    WebDriver driver;

    public void login() {

    System.out.println("Login print ");
    String title = driver.getTitle();
    System.out.println(title);
    }

    }
    ===================================================================================================================

    package com.JavaBasics;

    import org.openqa.selenium.WebDriver;

    public class CloseDriver {
    WebDriver driver;
    public void close() {
    driver.close();
    System.out.println("Close print");
    }

    }
    ==============================================================================================================================
    Console exception
    INFO: Detected dialect: W3C
    Exception in thread "main" java.lang.NullPointerException
    at com.JavaBasics.Login.login(Login.java:11)
    at com.JavaBasics.SeleniumTest.main(SeleniumTest.java:47)
     
    #30
  31. Diana Denis

    Diana Denis Member

    Joined:
    Apr 24, 2019
    Messages:
    5
    Likes Received:
    0
    Hi Anagha i need help something is not right and i do not know how to fix it. Thanks for any lead.
     

    Attached Files:

    #31
  32. Motilal Biswal

    Joined:
    Jul 29, 2019
    Messages:
    4
    Likes Received:
    3
    Hi Anagha,
    Please find the below assignments.

    Assignment 2:
    Create a current_account class inheriting it from Accounts.java. Add a calculate interest method like the one in saving_acc.java

    public class Account {
    int balance;
    public int deposit(int dep_amt) {
    balance=balance+dep_amt;
    return balance;
    }
    public double withdraw(int withdraw_amt) {
    balance=balance-withdraw_amt;
    return balance;
    }
    }

    public class Current_acc extends Account {
    int Acc_no;
    double interest;
    int balance;
    public double calc_interest_current(int balance) {
    interest = balance + (balance * 0.05);
    return interest;
    }
    }

    public class TestAccount {
    public static void main(String[] args) {
    int balance;

    Savings_acc myacc = new Savings_acc();
    myacc.Acc_no = 1234;
    balance = myacc.deposit(500);
    System.out.println("My savings account no:" + myacc.Acc_no);
    System.out.println("The savings account balance with interest: " + myacc.calc_interest_savings(balance));

    Current_acc myCurrentacc = new Current_acc();
    myCurrentacc.Acc_no = 9876;
    balance = myCurrentacc.deposit(1000);
    System.out.println("My current account no:" + myCurrentacc.Acc_no);
    System.out.println("The current account balance with interest: " + myCurrentacc.calc_interest_current(balance));
    }
    }

    Assignment 3:
    Implement abstract methods from Shape class into Circle class

    public abstract class Shape {
    public abstract void area(int a);
    public abstract void circum(int x, int y);
    public void DisplayColor(String color) {
    System.out.println("The color of shape is: " + color);
    }
    }

    public class Circle extends Shape {
    public static void main(String[] args) {
    Circle c = new Circle();
    c.area(10);
    c.DisplayColor("Blue");
    }
    @Override
    public void area(int a) {
    System.out.println("Area of circle is: " + a);
    }
    @Override
    public void circum(int x, int y) {
    }
    }
     
    #32
    Anagha Gadgil likes this.
  33. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20

    Your login class does not get the WebDriver instance. you will need to pass the WebDriver instance to login class. only then it will work.
    However you should create methods in the same class file instead of creating different class files.
    When we do the page object model, you will learn how to pass WebDriver instance to multiple classes
     
    #33
  34. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    For your chrome driver, check the Path of the driver. it should be ./Drivers/chromedriver.exe


    For the Firefox issue, please paste the complete exception.
    Also let me know the eclipse version. you can get this by going to About eclipse.
     
    #34
  35. Neena Gupta

    Neena Gupta Member

    Joined:
    Feb 20, 2019
    Messages:
    9
    Likes Received:
    4
    Neena's 2nd assignment:


    package com.simplilearnfolder.day1and2;

    public class CurrentAcct extends Account {

    double bal_w_interest;
    int currAcc_ID,balance;

    public double currAccInt(int balance) {
    bal_w_interest=(balance+(0.05*balance));
    return bal_w_interest;
    }

    }

    package com.simplilearnfolder.day1and2;

    public class TestAccount1 {

    public static void main(String[] args) {

    CurrentAcct myCurrAcc = new CurrentAcct();

    myCurrAcc.currAcc_ID = 5678;

    System.out.println("My current Account Id is : " + myCurrAcc.currAcc_ID);
    System.out.println("My balance with interest is : " + myCurrAcc.currAccInt(600));

    }

    }

    Result:
    My current Account Id is : 5678
    My balance with interest is : 630.0
     
    #35
  36. Simon Throup

    Simon Throup Member

    Joined:
    Jun 10, 2019
    Messages:
    10
    Likes Received:
    1
    Hello Anagha,

    I am attaching my first assignment, which has taken me a long time to prepare because I am not a Java developer. I added a few extra ways of printing output to the screen to understand how they work. The only thing I didn't do was make sure that the cursor is displayed on the lower line before typing starts when entering data or work out which is the larger number for the subtraction to avoid negative results. :)

    import java.util.Scanner;

    public class Assign1a {

    public static void main(String[] args) {

    // Declare variables

    int num1, num2, result;

    // To get input from the user using scanner class.

    Scanner inputobj = new Scanner(System.in);


    System.out.println("Enter your first name :");
    String fName = inputobj.nextLine();


    System.out.println("Enter first number : ");
    num1 = inputobj.nextInt();

    System.out.println("Enter second number : ");
    num2 = inputobj.nextInt();

    System.out.println("Hello : " + fName);
    System.out.println("You entered the following numbers ");
    System.out.println(+num1);
    System.out.println(+num2);

    //Test to see what happens if output is from here
    //result = num1 + num2;
    //System.out.println("The add result from Main Method is : " + result);

    Assign1a Assign = new Assign1a();
    Assign.Add(num1, num2);

    //Test to see what happens if the output comes from here
    System.out.println("Addition from Returned Value: " + Assign.Add(num1, num2));

    Assign.Sub(num1, num2);
    //Test to see what happens if the output comes from here
    System.out.println("Subtraction from Returned Value: " + Assign.Sub(num1, num2));

    Assign.Times(num1, num2);
    //Test to see what happens if the output comes from here
    System.out.println("Multiplication from Returned Value: " + Assign.Times(num1, num2));



    inputobj.close(); // close the object handler

    }

    // Method for adding two integers
    public int Add(int num1, int num2)
    {
    int addition = num1 + num2;
    System.out.println("The result of addition from Method Add is: "+addition);
    return num1 + num2;
    }

    // Method for subtracting two integers
    public int Sub(int num1, int num2)
    {

    int subtract = num1 - num2;
    System.out.println("The result of subtraction from Method Sub is: "+subtract);
    return num1 - num2;
    }

    // Method for multiplying two integers
    public int Times(int num1, int num2)
    {
    int subtract = num1 * num2;
    System.out.println("The result of multiplication from Method Times is: "+subtract);
    return num1 * num2;
    }
    }
     
    #36
  37. Simon Throup

    Simon Throup Member

    Joined:
    Jun 10, 2019
    Messages:
    10
    Likes Received:
    1
    Hello Anagha,

    Day 2 -Assignment 1.
    I have put into into a text file.rtf, because I do not know if there is a better way to attach the files. Each class is separated by a line. When I run it I get an error message, related to my attempt at using IF THEN and a String input. I can't seem to find a way around it. The error is related to the code in the MAIN method.

    The exact problem line is below, I want to check if the user has entered C for current account, if not, then it defaults to savings account behaviour.
    if (MyAccType.type.equalsIgnoreCase("C")) {

    I cannot attach .rtf files here though, can you help please, so I can attach everything and you can look at it?

    Thanks, Simon.
     
    #37
  38. Simon Throup

    Simon Throup Member

    Joined:
    Jun 10, 2019
    Messages:
    10
    Likes Received:
    1
    Day 2 - Assignment 2 = Abstract from shape into Circle

    Please let me know the format that you would like to see the assignments in. I assume that you do not want to actually mark them, but I would appreciate any feedback because I am very new to this. I tried to expand on this piece of work slightly because a circle does not have a lenght and width, you'll see that I included Radius, and then passed 0 where it was not used.
    Thank you.

    ----------------
    public abstract class D2_2ShapeAbstract {

    public abstract void area(int H, int W, int R);


    public abstract void circumferance(int x, int y, int r);


    public void displayColour (String colour) {
    System.out.println("The colour of shape is " + colour);
    };
    }

    -----------------

    public class D2_2Rectangle extends D2_2ShapeAbstract{


    @Override
    public void area(int H, int W, int R) {
    System.out.println("Area is x*y for rectangle : " + (H * W));

    }

    @Override
    public void circumferance(int x, int y, int r) {
    System.out.println("Circumferance is 2*x + 2*y for rectangle : " + ( (2*x) + (2*y)));
    }

    public static void main(String[] args) {
    D2_2Rectangle NewRec = new D2_2Rectangle();
    NewRec.circumferance(5, 5, 0);
    NewRec.area(5,5,0);
    NewRec.displayColour("red");
    }

    }
    -----------------

    public class D2_2Circle extends D2_2ShapeAbstract{

    @Override
    public void area(int H, int W, int R) {
    System.out.println("Circle area is (3.14 * (R*R)) for circle : " + (3.14 * (R * R)));
    }

    @Override
    public void circumferance(int x, int y, int r) {
    System.out.println("Circumferance is (2*3.14*R) for circle : " + ( 2 * 3.14 * r));

    }

    public static void main(String[] args) {
    D2_2Circle NewCirc = new D2_2Circle();
    NewCirc.circumferance(0, 0, 10);
    NewCirc.area(0,0,10);
    NewCirc.displayColour("blue");

    }

    }
    -----------------
     
    #38
    Anagha Gadgil likes this.
  39. Neena Gupta

    Neena Gupta Member

    Joined:
    Feb 20, 2019
    Messages:
    9
    Likes Received:
    4
    Neena's assignment on Abstract methods -

    package com.simplilearnfolder.day1and2;

    public class Circle extends ShapeAbtract {

    @Override
    public void area(int a, int b) {

    System.out.println("Area of circle with radius = " + a + " is " + Math.PI * a * a);

    }

    @Override
    public void circum(int a, int b) {
    System.out.println("Circumference of circle with radius = " + a + " is " + (2 * Math.PI * a));

    }

    public static void main(String[] args) {
    Circle obj = new Circle();

    obj.area(5,0);
    obj.circum(5, 0);
    obj.displayColor("Red");

    }

    }
     
    #39
    Simon Throup likes this.
  40. Chandrika S Naidu

    Joined:
    Mar 18, 2019
    Messages:
    4
    Likes Received:
    1
    Day 1 assignment

    import java.util.Scanner;

    public class Assignment1 {



    // TODO Auto-generated constructor stub
    public static void main(String args[])
    {
    Scanner in = new Scanner(System.in);
    int a = in.nextInt();
    System.out.println("You entered integer "+a);

    int b = in.nextInt();
    System.out.println("You entered integer "+b);

    System.out.println("adding 2 numbers " + a + ", " + b);
    System.out.println("result of addition is " + add(a,b));

    System.out.println("subtracting 2 numbers " + a + ", " + b);
    System.out.println("result of subtraction is " + subtract(a,b));

    System.out.println("multiply 2 numbers " + a + ", " + b);
    System.out.println("result of multiplication is " + multiply(a,b));

    }

    public static int add(int one, int two) {
    return one+two;

    }

    public static int subtract(int one, int two) {
    return one-two;

    }

    public static int multiply(int one, int two) {
    return one*two;

    }





    }
     
    #40
    Anagha Gadgil likes this.
  41. Simon Throup

    Simon Throup Member

    Joined:
    Jun 10, 2019
    Messages:
    10
    Likes Received:
    1
    Can anyone tell me why I should use a Try Catch exception for user entry rather than an if then statement that checks the user entry?
     
    #41
  42. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    You can always use if then statement. it was an example as how you can use exceptions to handle similar use case.
     
    #42
  43. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    Just copy paste the complete code here. Or zip the files and upload the zip file
     
    #43
  44. Anagha Gadgil

    Anagha Gadgil Well-Known Member

    Joined:
    Mar 18, 2019
    Messages:
    172
    Likes Received:
    20
    Here is the code for Searching in google and selecting from the displayed result.


    package com.simplilearn.day56;

    import java.util.List;
    import java.util.concurrent.TimeUnit;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;

    public class GoogleSearch {
    WebDriver driver;

    public void LaunchBrowser() {

    System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver"); // mac
    driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
    }

    public void search() throws InterruptedException {

    driver.get("https://www.google.com/");
    driver.findElement(By.name("q")).sendKeys("python tutorial");

    //Wait for the results to show up using thread.slepp
    //Thread.sleep(3000);

    //Wait for the results to show up using Explicit wait
    WebElement dropdownresult = (new WebDriverWait(driver, 10))
    .until(ExpectedConditions.presenceOfElementLocated(By.className("erkvQe")));

    List<WebElement> results = driver.findElements(By.xpath("//ul[@class='erkvQe']/li"));

    for (WebElement ele : results) {
    System.out.println(ele.getText());
    if (ele.getText().equalsIgnoreCase("python tutorial pdf")) {
    ele.click();
    break;

    }

    }

    }

    public static void main(String[] args) throws InterruptedException {
    GoogleSearch obj = new GoogleSearch();
    obj.LaunchBrowser();
    obj.search();

    }

    }
     
    #44
    Motilal Biswal likes this.
  45. Rupali_14

    Rupali_14 Member

    Joined:
    Jun 28, 2017
    Messages:
    9
    Likes Received:
    1
    Hi Anagha

    I was trying for our project but I am getting "org.openqa.selenium.StaleElementReferenceException:" when i try to search a text and again implement some functions on the search like clearing the search bar. but the url got changed after searching.
    How can we handle this?
     
    #45
  46. Neena Gupta

    Neena Gupta Member

    Joined:
    Feb 20, 2019
    Messages:
    9
    Likes Received:
    4
    Hi Anagha,

    Below code is not working for me to get DOB in Project website. Had tried for month and years and had the same issue. But it worked fine for state dropdown.


    Select daydrop = new Select(driver.findElement(By.id("days")));
    daydrop.selectByVisibleText("15");
     
    #46
  47. Motilal Biswal

    Joined:
    Jul 29, 2019
    Messages:
    4
    Likes Received:
    3
    Hi Anagha,
    Please find the below assignments:

    Assignment 3: Write a simple java program to print the text from the FB login page : “”create an account”

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;

    public class LocateCreateAccount {
    WebDriver driver;
    WebElement we;
    public void launchbrowser() {
    System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver.exe");
    driver = new FirefoxDriver();
    }
    public void test() {
    driver.get("https://www.facebook.com/");
    we = driver.findElement(By.xpath("//span[contains(text(),'Create an account')]"));
    System.out.println(we.getText());
    }
    public static void main(String[] args) {
    LocateCreateAccount obj = new LocateCreateAccount();
    obj.launchbrowser();
    obj.test();
    }
    }

    Assignment 4: Accept day, month and year from the user. Select the day month and year on the FB login page. Print the selected day month and year on the console

    import java.util.Scanner;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.Select;

    public class Birthday {

    WebDriver driver;
    WebElement We;

    public void launchbrowser() {
    System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver.exe");
    driver = new FirefoxDriver();
    }

    public void dropdown(int d, String m, String yr) {

    driver.get("https://www.facebook.com/");

    We = driver.findElement(By.id("day"));
    Select se_day = new Select(We);
    se_day.selectByIndex(d);
    System.out.println("Selected day is: " + se_day.getFirstSelectedOption().getText());

    We = driver.findElement(By.xpath("//select[@id='month']"));
    Select se_mon = new Select(We);
    se_mon.selectByVisibleText(m);
    System.out.println("Selected month is: " + se_mon.getFirstSelectedOption().getText());

    We = driver.findElement(By.xpath("//select[@id='year']"));
    Select se_yr = new Select(We);
    se_yr.selectByValue(yr);
    System.out.println("Selected year is: " + se_yr.getFirstSelectedOption().getText());
    }

    public static void main(String[] args) {

    Birthday obj = new Birthday();

    Scanner sc = new Scanner(System.in);

    System.out.print("Enter birthday day: ");
    int day = sc.nextInt();
    sc.nextLine();

    System.out.print("Enter birthday month: ");
    String month = sc.nextLine();

    System.out.print("Enter birthday year: ");
    String year = sc.nextLine();
    sc.close();

    obj.launchbrowser();
    obj.dropdown(day, month, year);
    }
    }
     
    #47
    Anagha Gadgil likes this.
  48. Neena Gupta

    Neena Gupta Member

    Joined:
    Feb 20, 2019
    Messages:
    9
    Likes Received:
    4
    I got it. Used selectByValue instead of selectByVisible


    selectby
     
    #48
  49. Neena Gupta

    Neena Gupta Member

    Joined:
    Feb 20, 2019
    Messages:
    9
    Likes Received:
    4
    Assignment #3: Write a simple java program to print the text from the FB login page : “”create an account”

    package com.simplilearnfolder.day3and4;

    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;

    public class FBcreateAcc {

    WebDriver driver;
    WebElement header;

    public void LaunchBrowser() {

    System.setProperty("webdriver.gecko.driver", "./Drivers/geckodriver.exe");
    driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);
    }

    public void LaunchURL() {
    driver.get("https://www.facebook.com/login");
    }

    public void CreateAcc() {
    header = driver.findElement(By.xpath("//a[@class='_42ft _4jy0 _4jy6 _4jy2 selected _51sy']"));
    System.out.println(header.getText());

    }

    public static void main(String[] args) {
    FBcreateAcc obj = new FBcreateAcc();
    obj.LaunchBrowser();
    obj.LaunchURL();
    obj.CreateAcc();

    }

    }
     
    #49
    Anagha Gadgil likes this.
  50. Neena Gupta

    Neena Gupta Member

    Joined:
    Feb 20, 2019
    Messages:
    9
    Likes Received:
    4
    Assignment # 4 :
    Accept day, month and year from the user.
    Select the day month and year on the FB login page.
    Print the selected day month and year on the console

    package com.simplilearnfolder.day3and4;

    import java.util.concurrent.TimeUnit;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.Select;
    import java.util.Scanner;

    public class FBuserDOB {

    WebDriver driver;
    WebElement web;

    public void LaunchBrowser() {

    System.setProperty("webdriver.gecko.driver", "./Drivers/geckodriver.exe");
    driver = new FirefoxDriver();

    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(90, TimeUnit.SECONDS);

    }

    public void bdaydrops(int month, int day, String year) {

    web = driver.findElement(By.name("birthday_month"));
    Select user_month = new Select(web);
    user_month.selectByIndex(month);
    System.out.println("User month of birthday is: " + user_month.getFirstSelectedOption().getText());

    web = driver.findElement(By.id("day"));
    Select user_day = new Select(web);
    user_day.selectByIndex(day);
    System.out.println("User day of birthday is: " + user_day.getFirstSelectedOption().getText());

    web = driver.findElement(By.xpath("//select[@id='year']"));
    Select user_year = new Select(web);
    user_year.selectByValue(year);
    System.out.println("User year of birthday is: " + user_year.getFirstSelectedOption().getText());
    }

    public void LaunchURL() {
    driver.get("https://www.facebook.com/");
    }

    public static void main(String[] args) {

    FBuserDOB obj = new FBuserDOB();
    Scanner scan = new Scanner(System.in);

    System.out.print("Enter month of Birthday: ");
    int month = scan.nextInt();
    scan.nextLine();

    System.out.print("Enter day of Birthday: ");
    int day = scan.nextInt();
    scan.nextLine();

    System.out.print("Enter year of Birthday: ");
    String year = scan.nextLine();
    scan.close();

    obj.LaunchBrowser();
    obj.LaunchURL();
    obj.bdaydrops(month, day, year);

    }

    }
     
    #50
    Anagha Gadgil likes this.

Share This Page