I have an xpath which works perfectly fine. Here is my code:
driver.find_element_by_xpath('//div[contains(text(), "aots-cm")]').click()
But "aots-cm" is a hard coded value. I want to pass a variable instead of hard coded value.
assetId = ("aots-cm")
my_var = ("'//div[contains(text()," + " " + '"' + assetId+ '"' + ")]'")
print (my_var)
=== > '//div[contains(text(), "aots-cm")]' ==> looks ok to me
driver.find_element_by_xpath(my_var).click()
There is error message Given xpath expression "'//div[contains(text(), "aots-cm")]'" is invalid: TypeError: The expression cannot be converted to return the specified type.