0

I have following HTML, I want to click the a tag with text MOUNT TAMALPAIS SP, CA the href is actually a javascript method. Below are details:

Code

keyword = 'MOUNT TAMALPAIS SP'    
link_text = wait.until(EC.visibility_of_element_located((By.PARTIAL_LINK_TEXT, keyword)))

HTML

<div id="facilities_suggestions_list" class="suggestions_list">
   <h3>Experience</h3>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120063:-122.595:37.9038889::CA&quot;, &quot;120063&quot;, 1 )" id="suggestion_1_120063"><strong>MOUNT</strong> <strong>TAMALPAIS</strong> <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120061:-121.93:37.8627778::CA&quot;, &quot;120061&quot;, 1 )" id="suggestion_1_120061"><strong>MT.</strong> DIABLO <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120062:-116.675:33.8102778::CA&quot;, &quot;120062&quot;, 1 )" id="suggestion_1_120062"><strong>MT.</strong> SAN JACINTO <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;NRSO:70045:-106.2227778:38.7141667::CO&quot;, &quot;70045&quot;, 1 )" id="suggestion_1_70045"><strong>MOUNT</strong> PRINCETON <span>, CO</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;NRSO:70124:-111.6036111:40.4061111::UT&quot;, &quot;70124&quot;, 1 )" id="suggestion_1_70124"><strong>MT.</strong> TIMPANOGOS <span>, UT</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281003:-81.2802778:29.8772222::FL&quot;, &quot;281003&quot;, 1 )" id="suggestion_1_281003">ANASTASIA <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120013:-122.3022222:37.2227778::CA&quot;, &quot;120013&quot;, 1 )" id="suggestion_1_120013">BUTANO <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;NE:230042:-103.0197222:42.7091667::NE&quot;, &quot;230042&quot;, 1 )" id="suggestion_1_230042">Chadron <strong>SP</strong> <span>, NE</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120035:-120.065:34.4622222::CA&quot;, &quot;120035&quot;, 1 )" id="suggestion_1_120035">GAVIOTA <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120048:-121.5694444:36.0530556::CA&quot;, &quot;120048&quot;, 1 )" id="suggestion_1_120048">LIMEKILN <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120049:-123.7925:39.4933333::CA&quot;, &quot;120049&quot;, 1 )" id="suggestion_1_120049">MACKERRICHER <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120052:-123.7113889:38.9738889::CA&quot;, &quot;120052&quot;, 1 )" id="suggestion_1_120052">MANCHESTER <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281060:-82.6033333:29.9194444::FL&quot;, &quot;281060&quot;, 1 )" id="suggestion_1_281060">OLENO <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;NE:230143:-96.7172222:42.6097222::NE&quot;, &quot;230143&quot;, 1 )" id="suggestion_1_230143">Ponca <strong>SP</strong> <span>, NE</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281076:-81.0836111:29.3408333::FL&quot;, &quot;281076&quot;, 1 )" id="suggestion_1_281076">TOMOKA <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281077:-84.9505556:30.5697222::FL&quot;, &quot;281077&quot;, 1 )" id="suggestion_1_281077">TORREYA <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120097:-123.7733333:39.2763889::CA&quot;, &quot;120097&quot;, 1 )" id="suggestion_1_120097">VANDAMME <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;NRSO:71897:-131.8988889:56.6441667::AK&quot;, &quot;71897&quot;, 1 )" id="suggestion_1_71897"><strong>MOUNT</strong> FLEMER CABIN <span>, AK</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;NRSO:75021:-82.7566667:35.4027778::NC&quot;, &quot;75021&quot;, 1 )" id="suggestion_1_75021"><strong>MOUNT</strong> PISGAH CAMPGROUND <span>, NC</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;NRSO:70459:-119.8973611:39.3122778::CA&quot;, &quot;70459&quot;, 1 )" id="suggestion_1_70459"><strong>MOUNT</strong> ROSE (NV) <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;NRSO:71896:-132.2391667:56.6644444::AK&quot;, &quot;71896&quot;, 1 )" id="suggestion_1_71896"><strong>MOUNT</strong> RYNDA CABIN <span>, AK</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120003:-122.4308333:37.8641667::CA&quot;, &quot;120003&quot;, 1 )" id="suggestion_1_120003">ANGEL ISLAND <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281005:-81.2741667:24.6597222::FL&quot;, &quot;281005&quot;, 1 )" id="suggestion_1_281005">BAHIA HONDA <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281128:-87.4038889:30.3180556::FL&quot;, &quot;281128&quot;, 1 )" id="suggestion_1_281128">BIG LAGOON <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281008:-86.8783333:30.7116667::FL&quot;, &quot;281008&quot;, 1 )" id="suggestion_1_281008">BLACKWATER RIVER <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281101:-81.3338889:28.9508333::FL&quot;, &quot;281101&quot;, 1 )" id="suggestion_1_281101">Blue Spring <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281010:-82.8197222:28.0311111::FL&quot;, &quot;281010&quot;, 1 )" id="suggestion_1_281010">CALADESI ISLAND <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120016:-122.3505556:41.1711111::CA&quot;, &quot;120016&quot;, 1 )" id="suggestion_1_120016">CASTLE CRAGS <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120017:-121.1866667:37.6933333::CA&quot;, &quot;120017&quot;, 1 )" id="suggestion_1_120017">CASWELL MEMORIAL <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281127:-82.2452778:26.6858333::FL&quot;, &quot;281127&quot;, 1 )" id="suggestion_1_281127">CAYO COSTA <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120018:-122.4605556:38.0008333::CA&quot;, &quot;120018&quot;, 1 )" id="suggestion_1_120018">CHINA CAMP <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:124900::::CA&quot;, &quot;124900&quot;, 1 )" id="suggestion_1_124900">CHINO HILLS <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120019:-122.8141667:39.0066667::CA&quot;, &quot;120019&quot;, 1 )" id="suggestion_1_120019">CLEAR LAKE <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281013:-81.5913889:25.9916667::FL&quot;, &quot;281013&quot;, 1 )" id="suggestion_1_281013">COLLIER-SEMINOLE <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281228:-80.985:24.7422222::FL&quot;, &quot;281228&quot;, 1 )" id="suggestion_1_281228">CURRY HAMMOCK <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120023:-116.5616667:32.9358333::CA&quot;, &quot;120023&quot;, 1 )" id="suggestion_1_120023">CUYAMACA RANCHO <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120029:-120.2419444:39.32::CA&quot;, &quot;120029&quot;, 1 )" id="suggestion_1_120029">DONNER MEMORIAL <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120031:-120.0930556:38.9544444::CA&quot;, &quot;120031&quot;, 1 )" id="suggestion_1_120031">EMERALD BAY <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281021:-85.5288889:30.7308333::FL&quot;, &quot;281021&quot;, 1 )" id="suggestion_1_281021">FALLING WATERS <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281241:-82.9347222:29.5861111::FL&quot;, &quot;281241&quot;, 1 )" id="suggestion_1_281241">FANNING SPRINGS <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281022:-81.2686111:29.6675::FL&quot;, &quot;281022&quot;, 1 )" id="suggestion_1_281022">FAVER-DYKES <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281025:-85.2133333:30.8088889::FL&quot;, &quot;281025&quot;, 1 )" id="suggestion_1_281025">FLORIDA CAVERNS <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281027:-81.4347222:30.67::FL&quot;, &quot;281027&quot;, 1 )" id="suggestion_1_281027">FORT CLINCH <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;NE:230077:-103.4941667:42.6866667::NE&quot;, &quot;230077&quot;, 1 )" id="suggestion_1_230077">Fort Robinson <strong>SP</strong> <span>, NE</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120209:-121.5013889:36.7608333::CA&quot;, &quot;120209&quot;, 1 )" id="suggestion_1_120209">FREMONT PEAK <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281033:-86.1566667:30.3294444::FL&quot;, &quot;281033&quot;, 1 )" id="suggestion_1_281033">GRAYTON BEACH <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281186:-86.4466667:30.3852778::FL&quot;, &quot;281186&quot;, 1 )" id="suggestion_1_281186">HENDERSON BEACH <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120040:-123.485:39.085::CA&quot;, &quot;120040&quot;, 1 )" id="suggestion_1_120040">HENDY WOODS <strong>SP</strong> <span>, CA</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281036:-81.5305556:27.4711111::FL&quot;, &quot;281036&quot;, 1 )" id="suggestion_1_281036">HIGHLANDS HAMMOCK <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
   <div class="facility_suggestion"><a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;FL:281037:-82.2269444:28.1430556::FL&quot;, &quot;281037&quot;, 1 )" id="suggestion_1_281037">HILLSBOROUGH RIVER <strong>SP</strong> <span>, FL</span></a>&nbsp;</div>
</div>

Update

The link of function is given here: http://pastebin.com/tfny2xdJ

12
  • Does this link = wait.until(EC.element_to_be_clickable((By.XPATH, "//a[.=keyword]"))) works? Commented Dec 21, 2016 at 8:55
  • 'MOUNT TAMALPAIS SP' isn't your search keywords. Get source code with selenium and check which values can be returned. Search all links of page for printing contained text pattern. Different encoding pattern got different results, so be careful on decoding.. Commented Dec 21, 2016 at 8:56
  • @Andersson No and most prolly because <a> contains <strong> as well? Commented Dec 21, 2016 at 8:58
  • @dsgdfg Yeah, the HTML is <a href="javascript:UnifSearchEngine.selectResolvedAddress(&quot;CA:120063:-122.595:37.9038889::CA&quot;, &quot;120063&quot;, 1 )" id="suggestion_1_120063"><strong>MOUNT</strong> <strong>TAMALPAIS</strong> <strong>SP</strong> <span>, CA</span></a> Commented Dec 21, 2016 at 8:58
  • @Volatil3, no, this shouldn't be a problem... Is there any exceptions? Commented Dec 21, 2016 at 8:59

2 Answers 2

3

If you cannot click link using click() method, try following code instead:

keyword = 'MOUNT TAMALPAIS SP'    
link_text = wait.until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, keyword)))    
driver.execute_script('arguments[0].click()', link_text)
Sign up to request clarification or add additional context in comments.

Comments

1

The text is actually divided between 4 different child elements of the <a> tag you are trying to click. You can use xpath to get it base on all the text in the child elements

keyword = 'MOUNT TAMALPAIS SP, CA'
keywords = keyword.split(' ')
link_text = wait.until(EC.visibility_of_element_located((By.XPATH, '//a[strong[contains(text(), "' + keywords[0] + '")] and strong[contains(text(), "' + keywords[1] + '")] and strong[contains(text(), "' + keywords[2] + '")] and span[contains(text(), "' + keywords[3] + '")]]')))

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.