Victor Johnzon
Victor Johnzon

Reputation: 225

passing dataframe data to python selenium xpath

I have a xpath into which I need to add a variable data:

browser.find_element_by_xpath("//span[contains(@class,'urLblPadding') and contains(text(),'"+notif_status_name+"')]").click()

If I pass data directly, then it will work. Else I get an error. I checked data from dataframe. It is showing correct data only.

Error:

File "C:\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)

I tried this :

browser.find_element_by_xpath("//span[contains(@class,'urLblPadding')[contains(text(),'%s')]" % notif_status_name']).click()

I got error :

SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//span[contains(@class,'urLblPadding')[contains(text(),'0    UYTY
Name: notif_status, dtype: object')]' is not a valid XPath expression.

Here UYTY is what I want. But it adds 0 UYTY

Upvotes: 0

Views: 113

Answers (1)

olli_kahn
olli_kahn

Reputation: 167

your syntax is incorrect. try:

browser.find_element_by_xpath("//span[contains(@class,'urLblPadding')[contains(text(),'%s')]" % notif_status_name).click()

the issue is that you've messed with quotes.

Upvotes: 1

Related Questions