I want to click the selenium (python) button on javascript in the following URL in Internet Explorer.


How can I click it?

  • Answer # 1

    As you may already know, I happened to find this question and write it down.
    You can click the javascript button with just selenium.
    First, get the element by tag or something, and get the coordinates of the target element.
    Click that coordinate using ActionChains.
    I put a reference code below.

    from selenium.webdriver.common.action_chains import ActionChains
    elements = driver.find_elements_by_tag_name ("a")
    loc = elements [0] .location
    x, y = loc ['x'], loc ['y']
    actions = ActionChains (driver)
    actions.move_by_offset (x, y)
    actions.click ()
    actions.perform ()

  • Answer # 2

    I think onclick = "xxxxxxxx" is written at the button.
    It works if you run javascript directly on selenium.
    You can copy and paste the entire area surrounded by "".

    driver.execute_script ("xxxxxxxx")

  • Answer # 3

    To click the button provided by javascript, selenium must have been impossible ...

    When I had the same problem before, I installed "PhantomJS" and managed it using the following. (First, install PhantomJS)

    from selenium import webdriver
    url = http://netspeed-tokyo.studio-radish.com/speedtest.html?mode=rw&precision=hi&type=l
        # Start PhantomJs in Internet Explorer
    driver = webdriver.Ie ()
        # access url
    driver.get (url)
        # Find the element properly and click
    driver.find_element_by_something ("button"). click ()

    If you do this, you can also click the javascript button
    ...... But this example page uses a Java applet, so I don't know if it works properly.
    By the way, my environment didn't move because JAVA was not included in the first place.