Code:
driver.findelement(By.xpath(".//*[@id='js_2y']/div[4]/div[2]/div/div[2]/div/button")).click();
Every time I try by locating XPath, it's gives an exception, could not locate element.
May 04, 2016 8:35:29 PM org.openqa.selenium.support.ui.ExpectedConditions findElement
WARNING: WebDriverException thrown by findElement(By.xpath: .//*[@id='js_2y']/div[4]/div[2]/div/div[2]/div/button)
Is it something that can be done using CSS selector. Not sure how to locate it. I see below path for it:
<button class="_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft" data-testid="react-composer-post-button" type="submit" value="1">
3 Answers 3
If you are asking about this post button - try below code to click on post button.
for this-
WebElement postBtn = driver.findElement(By.xpath("//button[contains(.,'Post')]"));
postBtn.click();
OR
WebElement postBtn = driver.findElement(By.xpath("//button[@class='_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft']"));
postBtn.click();
Inspect the element with below xpath locator :
By.xpath("//*[contains(@class, '_1mf7 _4jy0 _4jy3 _4jy1 _51sy selected _42ft') and @type='submit']");
Hope it will help resolve your problem.
I tried this just now.
Here my code:
browser.find_element_by_css_selector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft").click()
-
2Can you please explain why that worked? What benefit does that solution give over other options?ECiurleo– ECiurleo2017年09月04日 10:36:20 +00:00Commented Sep 4, 2017 at 10:36
Explore related questions
See similar questions with these tags.