1

I have no idea how to click this button. It has identifiers such as an image and text but i'm not sure how i use those to my advantage.

I've tried using the XPATH, i've tried using the text, i've tried using the link of the image, and i cant quite get it to work

MY CODE:

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Continue Watching"))).click()

BUTTON HTML:

<button style="margin-top: 15px;
            width: 240px;
            height: 46px;
            background-color: #69b8d6;
            margin: 50px auto;
            border-radius: 4px;
            color: white;
            display: block;
            margin-left: 159px;
            font-size: 16px;"><img style="padding-right:15px;" src="http://img.encrave.tv/global/watchCamcorder.png">Continue Watching</button>

My apologies if this button html turns into an actual button im not really sure how to deal with that.

My expected results are to "Find and wait for the button to be clickable." and then click it. My actual results are nothing happens and an error pops up in the console.

raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=49951): Max retries exceeded with url: /session/4100d1e939db4a44f287a50f5e9be234/element (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

4 Answers4

3

For me, I was killing the driver instance before the element could communicate. So just confirm once if it's not what happening with your code somewhere in config/setup.

0

Well you trying t find it by LINK_TEXT and is not a link

Can try this By.xpath("//*[text()='Continue Watching']"

nonyck
  • 69
  • 1
  • 13
0

To click() on the desired element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button>img[src*='tv/global/watchCamcorder']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[normalize-space() = 'Continue Watching']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

PS: However, the error you are seeing as No connection could be made because the target machine actively refused it is due to some other reasons and you can find a detailed discussion in MaxRetryError: HTTPConnectionPool: Max retries exceeded (Caused by ProtocolError('Connection aborted.', error(111, 'Connection refused')))

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

I was having a similar error, but then I realize that I was closing the driver in a tear-down and after I was trying to delete cookies... and was sending the error.

What I suggest is to look at your code and verify if in some instruction you are closing the driver.

Also another suggestion is to put a sleep after clicking your button.

If is possible try to implement the highlight to elements is very helpful on this situations.