1

Website

Website

myList = ['Artik']

How can I check if content of myList is visible in website above?

<span class="ipo-TeamStack_TeamWrapper">Artik<span>

This is the webelement holding 'Artik' in the website.

My goal is to click the element containing 'Artik' and do some stuff after that.

0

2 Answers 2

1

This is how you find an element by xpath in selenium. I am using Firefox here but you can use Chrome as well.

from selenium import webdriver

myList = ['Artik']
driver = webdriver.Firefox() # or .Chrome()
driver.get('www.theWebsite.com')

current = driver.find_element_by_xpath('//span[@class="ipo-TeamStack_TeamWrapper"]').text
if current in myList:
    print('YAY')

driver.quit()
Sign up to request clarification or add additional context in comments.

Comments

0
driver.find_elements_by_xpath("//*[contains(text(), 'Artik')]")

this return WebElement list contain 'Artik'.
parameter(like 'Artik') is case sensitive.


if you are convinced 'Artik' is only one,

driver.find_element_by_xpath("//*[contains(text(), 'Artik')]").click()

this will find WebElement with 'Artik' and click.

6 Comments

driver.find_element_by_xpath("//*[contains(text(), 'Artik')]").click() works well. <br/>What if I wanted to use text from myList[0] instead of 'Artik'?<br/>driver.find_element_by_xpath('//*[contains(text(), myList[0])]').click()<br/>Will cause error.
Sorry for bad editing skills above. driver.find_element_by_xpath('//*[contains(text(), myList[0])]').click() does not cause error like I told above, but it does not click the correct element so it is not useful.
@Sane90 please refer to part 'String Formatting Operator' here driver.find_element_by_xpath("//*[contains(text(), '%s')]" % myList[0]).click()
Oh my, how did this not come to my mind at all. Thanks for the help. New here in the SO but gotta love how helpful fellow coders are.
@Sane90 if i helped to solve this problem, please check here.
|

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.