0

I am using selenium and python to learn about automation web testing.

I want to click on "Continue" button, while there is only span in it (I had learned that using id instead of span is so much easier) but in this case, I want to click the span.

I am using below code:

driver.find_element_by_xpath("//span[contains(@class,'mdBtn01Txt')][contains(text(),'Continue')]").click()

here is the element :

<div class="mdLYR12Inner01">
<a class="MdBtn01 mdBtn01 ExDisabled FnSubmitBtn" style="display:none" href="#" onclick="charge(this); return false;">
<span class="mdBtn01Inner">
<span class="mdBtn01Txt">
Continue <<<(I want to click this button)
</span>
</span>
</a>    
</div>
</footer>

But, I got this message below:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[contains(@class,'mdBtn01Txt')][contains(text(),'Continue')]"}
3
  • Try driver.find_element_by_css_selector(".mdBtn01Txt").click() Commented Oct 14, 2019 at 10:41
  • hi, it seems doesnt work, i got this messageraise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".mdBtn01Txt"} Commented Oct 15, 2019 at 2:11
  • hi, thanks for your answer. I already solved this issue. so, in this case, the element are in pop up window, I assume the script won't execute the element. so, I redirect the pop up window link into my main window and then execute the element in it and it works. thanks again and sorry for my bad English. Commented Oct 15, 2019 at 3:38

1 Answer 1

4

Does not looks like a valid xpath, correct one should be

//span[@class='mdBtn01Txt']

Here is the rule to create xpath Syntax for XPath:

XPath contains the path of the element situated at the web page. Standard syntax for creating XPath is:

Xpath=//tagname[@attribute='value']

  • Tagname: Tagname of the particular node.
  • @: Select attribute.
  • Attribute: Attribute name of the node.
  • Value: Value of the attribute.
Sign up to request clarification or add additional context in comments.

4 Comments

hi, thanks for your answer, but I still having same issue here : raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[@class='mdBtn01Txt']"}
hi, thanks for your answer. I already solved this issue. so, in this case, the element are in pop up window, I assume the script won't execute the element. so, I redirect the pop up window link into my main window and then execute the element in it and it works. thanks again and sorry for my bad English.
ideally you should not open pop up window link in your main window, you can switch to pop up window and then continue your tests. Here is a tutorial showing how to do it. techbeamers.com/switch-between-windows-selenium-python
Hi neeraj jain, thank you so much for your advice. it WORKS much better then I expected. Using window switch make me focused on window to continue running the test better than redirected the link on main window. Thank you.

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.