I've tried several ways, but I just cannot seem to get Selenium to resolve to this HTML element on a page:
<button class="btn__primary--large from__button--floating" data-litms-control-urn="login-submit" aria-label="Sign in" type="submit">Sign in</button>
The value is null according to the DOM, and there are multiple submits on the page.
I have tried by.class, by.xpath. I don't know what code to include as the rest of it resolves, and it's a third party page.
I have tried findElement By.xpath, By.class (with the class names), byTagName with any of the text in the element, and byValue which didn't work as there wasn't one.
webDriver.manage().window().maximize();
webDriver.get("https://www.linkedin.com/login?fromSignIn=false&trk=guest_homepage-basic_nav-header-signin");
Thread.sleep(4000);
WebElement username = webDriver.findElement(By.name("session_key"));
WebElement password = webDriver.findElement(By.name("session_password"));
username.sendKeys("xxxxxx");
password.sendKeys("xxxxxx");
WebElement submit = webDriver.findElement(By.xpath("//input[@type='submit']"));
submit.click();
2 Answers 2
You can use this xpath: //*[@id="organic-div"]/form/div[4]/button
I got this by opening the developer tools and selecting the element in the Elements tab and then right click > Copy. And here you have all the options to query the element. You can try all of them or the above xpath.
7 Comments
Use this xpath which is much more robust - //button[contains(text(),'Sign in')]
//input[@type='submit']obviously won't work, as it isn't aninput, but abutton.