Selenium 定位不可点击的元素
Selenium Locating Unclickable Element
我正在尝试定位某个元素,但无法单击它。 id 是(“save-all-conditionally”),但如果我点击它就不起作用。我尝试了 css.selector
、xpath
和所有其他方法,但没有任何效果!
尚未测试:
iframe = driver.find_elements_by_tag_name('iframe')
if len(iframe) == 1:
driver.switch_to.frame(iframe[0])
button = driver.find_element_by_id('save-all-conditionally')
if button:
button.click()
由于iframe没有id通过标签名获取,应该是一个iframe使用switch_to.frame
切换到iframe内容并获取点击按钮
试试这个代码,看看它是否有效:
ele = driver.find_element_by_xpath("//*[@id='save-all-conditionally']")
ele.click()
There are 2 frames, frame inside frame.
You would need to switch to parent frame then child frame.
here is the working code :
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://www.gmx.net/consent-management/")
driver.implicitly_wait(10)
firstFrame = driver.find_element_by_xpath("//iframe[@class='permission-core-iframe']")
driver.switch_to.frame(firstFrame)
driver.switch_to.frame(0)
driver.find_element_by_xpath("//button[@id='save-all-conditionally']").click()
我正在尝试定位某个元素,但无法单击它。 id 是(“save-all-conditionally”),但如果我点击它就不起作用。我尝试了 css.selector
、xpath
和所有其他方法,但没有任何效果!
尚未测试:
iframe = driver.find_elements_by_tag_name('iframe')
if len(iframe) == 1:
driver.switch_to.frame(iframe[0])
button = driver.find_element_by_id('save-all-conditionally')
if button:
button.click()
由于iframe没有id通过标签名获取,应该是一个iframe使用switch_to.frame
切换到iframe内容并获取点击按钮
试试这个代码,看看它是否有效:
ele = driver.find_element_by_xpath("//*[@id='save-all-conditionally']")
ele.click()
There are 2 frames, frame inside frame. You would need to switch to parent frame then child frame. here is the working code :
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://www.gmx.net/consent-management/")
driver.implicitly_wait(10)
firstFrame = driver.find_element_by_xpath("//iframe[@class='permission-core-iframe']")
driver.switch_to.frame(firstFrame)
driver.switch_to.frame(0)
driver.find_element_by_xpath("//button[@id='save-all-conditionally']").click()