0

im new to java selenuim, im trying to make an automate program that press on 'Connect' button on linkedin.

i tried to read a solution online with no succes.

i tried to use driver.findelement(by.id) and driver.findelement(by.class) and both didnt worked.

Thanks!

package org.example.linkedin;
import java.util.Scanner;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class MainPageTest {


    Scanner scan = new Scanner(System.in);

    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver", "C:\chromedriver.exe");
        login();
        Connect();
    }


    public static void login() throws InterruptedException {
        WebDriver driver = new ChromeDriver();
        Scanner scan = new Scanner(System.in);
        System.out.println("please enter userName ");
        String userName = scan.nextLine();
        System.out.println("please enter password");
        String password = scan.nextLine();
        driver.navigate().to("https://www.linkedin.com/uas/login");
        WebElement element = driver.findElement(By.id("username"));
        element.sendKeys(userName);
        WebElement element2 = driver.findElement(By.id("password"));
        element2.sendKeys(password);
        driver.findElement(By.className("mercado-button--primary")).click();
        WebElement element3 = driver.findElement(By.id("ember26"));
        element3.click();
        Thread.sleep(3000);
    }

    public static void Connect() throws InterruptedException {
      <button aria-label="Invite "" to connect" id="ember589" class="full-width artdeco-button artdeco-button--2 artdeco-button--full artdeco-button--secondary ember-view" type="button"><!---->
Connect } }
ohadHa
  • 1
  • 3

1 Answers1

0

Did you try to find the web element using XPATH,

Locate the element on the web page using the Chrome dev tools and copy the XPATH by right clicking on it.

And if the element is inside a frame or iframe, then you need to switch to that frame or iframe before clicking on it.

Make sure you don't get any pop ups on your webpage before clicking on the web element, as the pop up will be in focus and you will get an Element Not Iterateable exception.

Kumar Shivam Ray
  • 337
  • 2
  • 10