我有一个Instagram类按钮。
<button class = "aOOlW HoLwm "tabindex = "0">Non ora</button>==$0
我想承认并启用它。
我尝试:
element = browser.find_element_by_name("Non ora")
element = browser.find_element_by_class_name("aOOlW HoLwm ")
browser.find_element_by_xpath('//input[starts-with(@class,"aOOlW. HoLwm")]').click()
elem = browser.find_element_by_class_name("aOOlW HoLwm ")
elem.click()
这是我遇到的错误之一:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".aOOlW HoLwm "}
(会话信息:chrome=75.0.3770.100(
尽管在实现中有很多错误:
试试这个:
browser.find_element_by_xpath("//button[contains(@class, 'aOOlW') and contains(@class, 'HoLwm')]").click()
此外,您可以考虑等待元素可点击:
elem_path = "//button[contains(@class, 'aOOlW') and contains(@class, 'HoLwm')]"
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, elem_path)))