Click the javascript popup through webdriver

前端 未结 6 754
再見小時候
再見小時候 2020-12-05 10:58

I am scraping a webpage using Selenium webdriver in Python

The webpage I am working on, has a form. I am able to fill the form and then I click on the Submit button.

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 11:24

    I am using Ruby bindings but here what I found in Selenium Python Bindings 2 documentation: http://readthedocs.org/docs/selenium-python/en/latest/index.html

    Selenium WebDriver has built-in support for handling popup dialog boxes. After you’ve triggerd and action that would open a popup, you can access the alert with the following:

    alert = driver.switch_to_alert()
    

    Now I guess you can do something like that:

    if alert.text == 'A value you are looking for'
      alert.dismiss
    else
      alert.accept
    end
    

    Hope it helps!

提交回复
热议问题