简体   繁体   中英

Python Selenium Element does not exist

Been struggling to click a certain nested li in a ul. Each attempt throws an error. Im trying to use xpath however any approach would be welcome. Also take into consideration that there is some extra text after the span tag.

Script:

 driver.find_element_by_xpath("//label[text()=contains(span,'Tomorrow')]").click()

HTML

 <ul class="slide-flow">
 <li class="slide-flow__item">....</li>
 <li class="slide-flow__item">
 <div>
 <label class="radio" for="pack 2" data-track="2nd track">
 <div class="slide-flow__menu menu_brand">
 <strong>
 <span>Tomorrow</span>
 </strong>
 -Second Notataion
 </label>
 <span class="slide-flow__price">...</span>
 </div>
 </li>
 <li class="slide-flow__item"> ....</li>
 </ul>
  1. The spelling of "Tomorrow" is different in the XPath and HTML.
  2. In contains() function, try contains(., 'Tommorow') . Replace span with . .

Correct XPath will be (Check the spelling of "Tomorrow")

//label[text()=contains(.,'Tommorow')]

Because the entirety of the text in the SPAN is "Tommorow" (misspelled), you don't need contains() . The below works.

//span[text()='Tommorow']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM