I'm trying to locate a element, but I can't click on it. The id is ("save-all-conditionally"), but it's not working if I click on it. I tried css.selector
, xpath
and all other things, but nothing is working!
CodePudding user response:
Try this code, see if it works:
ele = driver.find_element_by_xpath("//*[@id='save-all-conditionally']")
ele.click()
CodePudding user response:
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()
CodePudding user response:
Not tested yet:
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()
Since the iframe has no id get it by tag name, it should be one iframe use switch_to.frame
to switch to the iframe content and get the button to click on it