1

I try to parse this site with chromedriver But there's a dialog box that messes up with that

SGX site

Is there a way to discard the dialog box or choose the No, thanks button?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
MMM
  • 910
  • 1
  • 9
  • 25
  • What problem are you running into? Can you post the selenium-webdriver code that you've written to solve this issue? – orde Sep 05 '19 at 21:24
  • I am not sure how to search for the dialog box, then how to extract from there the "No thanks" button to then click it? Not sure what the Xpath of that button would be? – MMM Sep 05 '19 at 21:29
  • You can wait and click a simple CSS selector, `button[data-analytics-action='Click Cancel']`, to dismiss the popup. – JeffC Sep 05 '19 at 23:25

1 Answers1

1

To click()on the element with text as No, thanks you have to induce WebDriverWait for the desired element_to_be_clickable() and you can use either of the following Locator Strategies:

  • CSS_SELECTOR:

    driver.get("https://www2.sgx.com/derivatives/delayed-prices-futures?cc=CN&category=equityindex")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.sgx-button--link[data-action='cancel'][data-analytics-action='Click Cancel']"))).click()
    
  • XPATH:

    driver.get("https://www2.sgx.com/derivatives/delayed-prices-futures?cc=CN&category=equityindex")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='sgx-button--link' and @data-action='cancel'][@data-analytics-action='Click Cancel']"))).click()
    
  • Browser Snapshot:

SGX

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