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!
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()
Try this code, see if it works:
ele = driver.find_element_by_xpath("//*[#id='save-all-conditionally']")
ele.click()
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
Related
I want to enter the "Symbol" name and select tab "NSE" from the filter. Once that is done, click on table view button using Selenium. But I cannot find any of these nodes using Debugger.
(https://i.stack.imgur.com/uOrQc.png)
The original class "chart-frame" is found.
driver.find_element(By.ID, "chart-iframe")
I get "No such element" for any of the below commands. I cannot find any information on this CQ tags online.
driver.find_element(By.CLASS_NAME, "ciq-search")
driver.find_element(By.CSS_SELECTOR, "ciq-search")
driver.find_element(By.CSS_SELECTOR, "ciq-DT.tableview-ui")
driver.find_elements(By.XPATH, '//button')
Firstly, you need to switch into that iframe to scrape whatever you wanna scrape. You can use following code snippet for it:
iframe = driver.find_element(By.XPATH, "//iframe[#name='TheIframeName']")
driver.switch_to.frame(iframe)
You can use driver.switch_to.default_content() to switch back to default content.
I am trying to scrap this webpage https://www.tecnocasa.es/venta/piso/barcelona/barcelona/510567.html, the code i use is the following, and i think is correct:
options = Options()
options.headless = False
driver = webdriver.Firefox(options=options, executable_path=r'geckodriver.exe')
driver.get(url)
# ("Headless Firefox Initialized")
#dins del id= cookie-banner
frame = driver.find_element(by=By.CSS_SELECTOR,value = '[id = "cookie-banner"]')
print(frame)
buttons = frame.find_elements(by=By.TAG_NAME, value='button')
print(buttons)
buttons[0].click()
time.sleep(5)
The buttons are found but when i try to click one i have the error <button class="btn-default"> is not clickable at point (1138,829) because another element <div id="hide-overlay" class="hide-overlay fade-leave-active fade-leave-to"> obscures it
How can i disable this overlay and click the button to accept the conditions of the page?
Your code works without any problem on my computer, try this one
driver.find_element(By.CSS_SELECTOR, '#close').click()
If also this will not work, you can try this code which hides the banner. However, you should run it each time that a new page is loaded
overlay = driver.find_element(By.CSS_SELECTOR, 'div.cookies-overlay')
driver.execute_script("arguments[0].style.display = 'none';", overlay)
banner = driver.find_element(By.CSS_SELECTOR, '#cookie-banner')
driver.execute_script("arguments[0].style.display = 'none';", banner)
https://www.gmx.net
I want to click on Zustimmen und weiter.
driver.get('https://www.gmx.net')
WebDriverWait(driver, 10).until(expected_conditions.frame_to_be_available_and_switch_to_it((By.XPATH, '/html/body/iframe')))
driver.find_element_by_xpath('//*[#id="save-all-conditionally"]').click()
The code above is not working for me.
Element you are trying to access is located inside nested iframe, one iframe insde another iframe.
You should switch to the first iframe, then to the inner iframe and then to click the "Get cookies" button.
This should work:
wait = WebDriverWait(driver, 20)
wait.until(expected_conditions.frame_to_be_available_and_switch_to_it((By.XPATH, '//iframe[#class="permission-core-iframe"]')))
wait.until(expected_conditions.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(#src,'plus')]")))
wait.until(EC.visibility_of_element_located((By.XPATH, '//*[#id="save-all-conditionally"]'))).click()
When you finished working inside that iframe you will have to switch to the default context with
driver.switch_to.default_content()
I'm trying to crawl a website for sports statistics, and realised all of the important data is inside an iframe. I use driver.switch_to.frame() to switch to the iframe and that doesn't throw any errors.
frame1 = '//iframe[#src="reallylongsource"]'
driver.switch_to.frame(driver.find_element_by_xpath(frame1))
But then when I try to access the information inside the iframe,
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: .//div[#class="classname"]
is raised. I can see that the element is there in the HTML but I can't find it with selenium. I've tried locating it with CSS selector as well with no success.
I'm quite sure it's the correct iframe as well. I've tried finding it both with the xpath and by tag name and they were the same iframe.
When I print
print(driver.find_element_by_xpath(frame1).text)
I only get blank space
I've been butting my head against the wall for quite a while now and can't figure it out!
It seems like I'm able to switch to the correct iframe, but selenium can't find any information within it.
try use like this:
driver = webdriver.Chrome()
driver.get(URL)
driver.implicitly_wait(5)
driver.switch_to.frame(driver.find_element(By.TAG_NAME, 'iframe'))
element = driver.find_element(By.XPATH, '//div[#class="classname"]')
driver.quit()
if it's the same what you're doing in your code, please provide more info to take a look of the page
try this, it will move to the first game of first type game and get all of the scores and prints it:
import time
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('https://campobet.se/en/sport/prelive?sportids=66')
time.sleep(5)
driver.switch_to.frame(
driver.find_element_by_xpath("//iframe[contains(#src, 'https://sb1client-altenar.biahosted.com')]"))
time.sleep(1)
game_types = driver.find_elements_by_xpath("//div[#name='leagues-selector']")
time.sleep(1)
game_types[0].click()
time.sleep(1)
games = driver.find_elements_by_xpath(
"//div[#class='_asb_simple-button _asb_simple-button-pointer _asb_leagues-selector-item ']")
games[0].click()
time.sleep(1)
scores = driver.find_elements_by_xpath("//div[#class='asb-flex-cc asb-unshrink _asb_price-block-content-price ']/span")
time.sleep(1)
scores_values = [el.text for el in scores]
time.sleep(1)
print(scores_values)
driver.quit()
I have all of my options selected on this form and have the following code to click the Search button:
WebDriverWait(wd, 10).until(EC.element_to_be_clickable((By.ID, "alMatchFrequencies"))).click()
I have also tried this:
search = WebDriverWait(wd, 10).until(EC.element_to_be_clickable((By.ID, "alMatchFrequencies")))
search.send_keys(Keys.ENTER)
I have also tried subbing in RETURN instead of ENTER.
Here is a screenshot after that line is run:
The search bar is highlighted, but no results are being displayed. I can replicate this screen on my own and am able to press the search button so I don't think it is missing fields.
I believe you are actually clicking the search button but are not seeing the results because they are below the view you show. The scrollable area in your screenshot was a clue.
Clicking the search button is as easy as search.click() after you've executed the selector. But then you need to wait and scroll the page.
To Scroll a page you need to introduceActionChains in the Selenium library and to wait for the load you'll need to use Python's time.sleep(sec) function.
Full code to produce the attached picture:
#Imports
import time
from selenium.webdriver.common.action_chains import ActionChains
#...Code to Load and Select Filters...#
search = WebDriverWait(wd, 3000).until(EC.element_to_be_clickable((By.ID, "alMatchFrequencies")))
search.click()
# Wait for element to load
time.sleep(3)
# Locate element to scroll to
results = WebDriverWait(wd,3000).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[1]/section/div/div[2]/div/div[2]/div[5]/div/div[1]/div[5]")))
actions = ActionChains(wd)
# Scroll
actions.move_to_element(results).perform()
wd.get_screenshot_as_file("test3.png")