I want to click the parent of an element if the text within the child matches a certain string. I am using contains
to find the text and :xpath,"../../"
to find the parent.
Here is ruby code:
[email protected]_element(:xpath,"//*[contains(.,'602384710')]")
puts test
puts test.find_element(:xpath, "../..").click
The HTML snippet of the element I want to target is:
<a class="tv-card-link" href="/my-account/tv/overview?ban=7AhDHZ0ZYFVI1m8B2HmvrQ&tv_instance_id=_A5Xvou4fk-WsIWSnSkG2A">
<div class="tv-card-wrapper">
<div class="tv-card-icon"></div>
<div class="tv-card-details">
<div class="tv-card-id">
602384710
</div>
</div>
</div>
</a>
From the code, I want to click on the <a>
if I find the text 602384710
.
When I was testing, the puts test
prints out the address of Selenium WebElement so I know that works. However, selenium is unable to find the parent of the element. The error I get is:
Unable to locate element: {"method":"xpath","selector":"../.."} (Selenium::WebDriver::Error::NoSuchElementError)
[remote server] file:///C:/Users/X169804/AppData/Local/Temp/webdriver-profile20150407-7120-6gmcur/extensions/fxdriver@go
oglecode.com/components/driver-component.js:10271:in `FirefoxDriver.prototype.findElementInternal_'
[remote server] file:///C:/Users/X169804/AppData/Local/Temp/webdriver-profile20150407-7120-6gmcur/extensions/fxdriver@go
oglecode.com/components/driver-component.js:603:in `fxdriver.Timer.prototype.setTimeout/<.notify'
./features/step_definitions/ss-login_step.rb:26:in `/^I click on plan number (\d+)$/'
features\ss-login.feature:16:in `Then I click on plan number 602384710'
I think I may be missing a simple thing. Any help appreciated :)