2
 <div class="mdl-align"> == $0
    : :before
    <button class="fp-upload-btn btn-primary btn">Upload this file</button> == $0
    : :after
 </div>

The above codes are from a website, however I am unable to click this button despite trying multiple attempts. Im using selenium with C# to do an automation testing. What this button does, is to simply submit a form.

1
  • I'd recommend setting the id attribute on all components you want to manipulate using Selenium or any other UI Automation framework. Like @jainish kapadia said you can use XPath or CssSelectors like in jQuery but these rely on the layout, styling or even the language of the page. By setting the ID you don't have to worry about these variations provided the ids stay the same (the UI could be completely changed and it should still work.) Of course if you're crawling a page you don't own then XPath and CssSelectors are the best way I'm aware of. Commented Mar 17, 2017 at 8:53

1 Answer 1

6

Try to use xpath locator to click on Upload this file button.

driver.FindElement(By.XPath("//button[contains(text(), 'Upload this file')]")).Click();
Sign up to request clarification or add additional context in comments.

4 Comments

Hi, just saw your comment, I've tried and it works, may i know how you actually understand it? I'm very new in this
Your button is contains text as Upload this file So, Start your xpath with button tag and then use` text` method for find the element.
Fore more details on xpath, refer this link, w3schools.com/xml/xpath_intro.asp
@JainishKapadia can you please check this too.Thank u so much .stackoverflow.com/questions/77044226/…

Your Answer

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.