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">
Bulat
3003 silver badges9 bronze badges
asked May 5, 2016 at 0:53

3 Answers 3

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();
answered May 5, 2016 at 5:59
0
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.

Kate Paulk
31.5k8 gold badges56 silver badges109 bronze badges
answered Feb 6, 2018 at 18:41
0

I tried this just now.

Here my code:

browser.find_element_by_css_selector("._1mf7._4jy0._4jy3._4jy1._51sy.selected._42ft").click()
answered Sep 3, 2017 at 14:24
1
  • 2
    Can you please explain why that worked? What benefit does that solution give over other options? Commented Sep 4, 2017 at 10:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.