1

Trying to get the search bar in LinkedIn homepage or job search page. ain't working, have tried multiple locators

Home page search box Element:

<input class="search-global-typeahead__input" placeholder="Search" role="combobox" aria-autocomplete="list" aria-label="Search" aria-activedescendant="" aria-expanded="false" type="text">

jobs page search box element:

<input id="jobs-search-box-keyword-id-ember648" class="jobs-search-box__text-input jobs-search-box__keyboard-text-input" autocomplete="chrome-off" spellcheck="false" role="combobox" aria-autocomplete="list" aria-label="Search by title, skill, or company" aria-activedescendant="" aria-expanded="false" type="text">

code:

String partialId = "jobs-search-box-keyword-id-ember";
WebElement searchBox = driver.findElement(By.cssSelector("[id^='" + partialId + "']"));

code:

String partialId = "jobs-search-box-keyword-id-ember";
WebElement searchBox = driver.findElement(By.cssSelector("[id^='" + partialId + "']"));

expecting to find the element and enter search keyword to automate.

Shawn
  • 4,064
  • 2
  • 11
  • 23
  • Can we please get a [mcve]? – Robert Jun 29 '23 at 18:17
  • Please [edit the question](/posts/76583078/edit) to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the [How to Ask](https://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – undetected Selenium Jun 29 '23 at 20:22

1 Answers1

0

Please refer to the below code. It works for me: (I have used regular expression to define some XPath which are dynamic as example, id="jobs-search-box-keyword-id-ember648" -> this one every time changing). Also add wait to load the page after searching.

    WebDriverManager.chromedriver().setup();
    WebDriver driver=new ChromeDriver();
    driver.get("https://www.linkedin.com/authwall?trk=qf&original_referer=https://www.linkedin.com/feed/&sessionRedirect=https%3A%2F%2Fwww.linkedin.com%2Fhome");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(3000, TimeUnit.SECONDS);
    driver.findElement(By.id("email-or-phone")).sendKeys("test@gmail.com");
    driver.findElement(By.id("password")).sendKeys("test");
    driver.findElement(By.xpath("//button[starts-with(@class, 'authwall-join-form__form-toggle--bottom form-toggle')]")).click();
    driver.findElement(By.id("session_key")).sendKeys("test@gmail.com");
    driver.findElement(By.id("session_password")).sendKeys("test");
    driver.findElement(By.xpath("//button[starts-with(@class, 'btn-md btn-primary flex-shrink-0 cursor-pointer')]")).click();
    driver.findElement(By.xpath("//*[@id=\"global-nav-typeahead\"]/input")).sendKeys("google");
    driver.findElement(By.xpath("//*[@id=\"global-nav-typeahead\"]/input")).sendKeys(Keys.ENTER);
    driver.findElement(By.partialLinkText("Jobs")).click();
    driver.findElement(By.xpath("//input[starts-with(@id, 'jobs-search-box-keyword-id-ember')]")).sendKeys("hr");
    driver.findElement(By.xpath("//input[starts-with(@id, 'jobs-search-box-keyword-id-ember')]")).sendKeys(Keys.ENTER);
    driver.close();
arpita biswas
  • 144
  • 1
  • 6