user3194722 user3194722 - 6 months ago 12
Python Question

Selecting html element tag(?) name selenium python

I am writing a function in python3 using selenium that will click a link given that it matches a provided text, but having trouble figuring out how to do so. The html is as follows:

<a class="name-link" href="/colors/thisOne" </a>


Yellow


I do know how to select the class name
"find_element_by_class_name("name-link")
but how would I also include the text
Yellow
as an option as well, so that my if statement would be like:

if 'Yellow' == (variable):
.click()


Thank you in advance.

San San
Answer

Hope this one might help you solve the issue

find_element_by_link_text('Yellow')

Happy Coding :)