How to pass string to an XPath containing text?
问题 I get id of a text which is in selected mode using Selenium Webdriver by using this code: String requiredId = driver.FindElement(By.XPath("//option[@selected='selected' and .='Blue']/..")).GetAttribute("id"); How can i pass string getColour in place of Blue? Thank you 回答1: You can pass a string this way. Try below code string getColourin = "Red"; String requiredId = driver.FindElement(By.XPath("//option[@selected='selected' and .='" + getColourin +"']/..")).GetAttribute("id"); OR using string