Probably a pretty easy question:
I’m using Mechanize, Nokogori, and Xpath to parse through some html as such:
category = a.page.at("//li//a[text()='Test']")
Now, I want the term that I’m searching for in text()= to be dynamic…i.e. I want to create a local variable:
term = 'Test'
and embed that local ruby variable in the Xpath, if that makes sense.
Any ideas how?
My intuition was to treat this like string concatenation, but that doesn’t work out:
term = 'Test'
category = a.page.at("//li//a[text()=" + term + "]")
When you use
category = a.page.at("//li//a[text()=" + term + "]"). The final result to method is//li//a[text()=Test]where test is not in quotes. So to put quotes around string you need to use escape character\.or
or
For example: