Home > Software engineering >  Python Selenium-WebDriver - How to Identify this Button/Link
Python Selenium-WebDriver - How to Identify this Button/Link

Time:12-30

Please refer to the screenshot below and the HTML code. There are two buttons/links that have "Indiana -4.5" and "Indiana" in their name. I am trying to identify the first that also has "-4.5" however I will not know what that number is as it changes. The name "Indiana" can be followed by a " ", "-" which is then followed by a one or two digit decimal number.

Given only "Indiana" as a variable how can I select the "Indiana -4.5" and not "Indiana" link/button. Thank you!

Link to page: enter image description here

    def proline_go_to_match2(driver, team):
        team = "Indiana"
        print(team)
        try:
            match = WebDriverWait(driver, 15).until(
                EC.presence_of_element_located((By.XPATH, "//*[@title= '"   team    "']"))
            )
            match.click()
        except:
        driver.quit()

I cannot figure out how to get Seleium to identify this link and would appreciate your help!!

Here is the HTML element

Here is the first link/button:

<span  aria-pressed="true" role="button" tabindex="0" aria-label="Bet for Charlotte @ Indiana - Indiana -4.5 at 2.10" title="Indiana -4.5"><span >Indiana -4.5</span><span >2.10</span></span>

Here is the second link/button:

<li  title="Indiana" data-state="unselected" data-direction="" data-unpriced="false" data-hidden="false" data-resulted="false" data-suspended="false"><span  aria-pressed="false" role="button" tabindex="0" aria-label="Bet for Charlotte @ Indiana - Indiana at 1.65" title="Indiana"><span >Indiana</span><span >1.65</span></span></li>

CodePudding user response:

To click on the element Indiana -4.5 instead of Indiana

CodePudding user response:

You should use visibility_of_element_located instead of presence_of_element_located.
With the correct locator your code can be as following:

def proline_go_to_match2(driver, team):
    team = "Indiana"
    print(team)
    try:
        match = WebDriverWait(driver, 15).until(EC.visibility_of_element_located((By.XPATH, "//header[.//span[text()='Point Spread'] and .//span[contains(.,'Match')]]/..//li[contains(@title,'"   team    "')]"))            )
        match.click()
    except:
       driver.quit()
  • Related