pythonseleniumxpathcss-selectorslinktext

How do I select the an element without an ID/text_link/name in selenium?


HTML of the website

The HTML code of the element I want to select:

   <a href="../s-reminderNotice.asp?fname=b%2D3c%2DpLessonBooking%2Easp%3Flimit%3Dpl" class="sidelinkbold" 
   target="mainFrame" 
   onmouseover=" window.status='Practical Training Booking'; 
   return true" onmouseout="window.status=' ';
   return true">Booking without Fixed Instructor</a>

I would like to select the element of this "Booking without Fixed Instructor" ; however there isn't an ID/link_text/name for this element. How can I direct the site to the HREF. Is there a way to use xpath to locate it , the element is in the column on the left of the website so there are many other elements of the same class. (see pic.)

I tried this and it returned:

AttributeError: 'WebDriver' object has no attribute 'findElement'

Code:

driver.findElement(By.xpath("//a[@href='THE LINK']")).click();

SOLVED; ELEMENT WAS IN AN IFRAME ; HAD TO SWITCH FRAME TO ACCESS ELEMENT


Solution

  • To click on the element with text as Booking without Fixed Instructor you can use either of the following Locator Strategies:


    The desired element is a dynamic element, so ideally to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:


    References

    You can find a couple of relevant discussions on NoSuchElementException in: