简体   繁体   中英

Python / Selenium ; Unable to find element by class in Internet Explorer

I'm totally a newbie, trying to click in Inte.net Explorer using selenium in python. When I can see only class = "drop_text2" from inspect element in Inte.net Explorer, how can I type the code to click that?

This is my script:

driver.find_element_by_class_name('drop_text2').click()

and inspect element in Inte.net Explorer:

<span class="drop_text2">Matrix</span>

Could you explain to me what I'm doing wrong?

First, wait for the page to fully load, then you may need to perform the click operation twice to make it work.

Here is a simple demo:

    <span class="drop_text2" onclick="myFunction()">Matrix</span>
    <script>
        function myFunction() {
            window.alert('You clicked me!');
        }
    </script>

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


ser = Service(r"C:\\Users\\Administrator\\Desktop\\IEDriverServer.exe")
driver = webdriver.Ie(service = ser)
driver.get("https://localhost:44356/Index.html")
wait_time = 60 # wait for page to load
element = WebDriverWait(driver, wait_time).until(EC.element_to_be_clickable((By.CLASS_NAME,"drop_text2")))
element.click()
element.click()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM