1

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">
4

If you are asking about this post button - try below code to click on post button.

enter image description here

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();
1

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.

0

I tried this just now.

Here my code:

browser.find_element_by_css_selector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft").click()
  • 2
    Can you please explain why that worked? What benefit does that solution give over other options? – ECiurleo Sep 4 '17 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.