1

The link I would like to click is input by the user. For example the user inputs for variable track, "Tampa Bay Downs"

My python selenium test program will search the code below:

<a ng-click="updateFavorite()(raceInfo.trackAbbr); $event.stopPropagation();">EV
  i class="my-icon-favorite-fill my-icon-favorite-fill_active" ng-class="{
  'my-icon-favorite-fill' : !showActionFeedback, ...onFeedback, 'rotating spinner' :
  showActionFeedback}" update-favorite-action-feedback="" qa-label="race-favorite-icon">
    ::before
   </i>
</a>
<span class="ng-binding" ng-bind="::raceInfo.trackName" qa-label="race-track-name">
Tampa Bay Downs</span>
</td>

The successful code will find the input words "Tampa Bay Downs" and then click it to activate an angularjs action that would cause a separate page to open, which is the desired action.

I have tried to find the link using the correct xpath with no success.
I have also tried this with no success:

try:
    element = driver.find_element_by_css_selector("a[qa-label="+track+"]")
except:
    print "error finding css selector for track"
5
  • You can try by xpath with "//span[contains(.,'{}')]/preceding-sibling::a".format(track) or use the class name to be more specific "//span[@qa-label='race-track-name' and contains(.,'{}')]/preceding-sibling::a".format(track) Commented Mar 20, 2016 at 20:26
  • 1
    Also don't use blanket except statements, catch what you expect. Commented Mar 20, 2016 at 20:32
  • Thanks for the prompt reply (and suggestion) Padraic, I'm giving that a try now. Commented Mar 20, 2016 at 20:57
  • It worked. If you send your answer as an answer, I will check it. Many thanks! Commented Mar 20, 2016 at 21:26
  • No worries, I added it as an answer. Commented Mar 20, 2016 at 21:34

1 Answer 1

1

You can select using an xpath using preceding-sibling to find the a before the span tag that contains the track name i.e Tampa Bay Downs:

"//span[contains(.,'{}')]/preceding-sibling::a".format(track) 

Or more specifically using the span class name:

 "//span[@qa-label='race-track-name' and contains(.,'{}')]/preceding-sibling::a".format(track) 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.