I am trying with :
driver.find_element_by_xpath("//input[#type='checkbox']").click()
The input is inside an iframe you need to switch iframe first in order to access the input element.
Use WebDriverWait() and wait for frame_to_be_available_and_switch_to_it()
Use WebDriverWait() and wait for input element_to_be_clickable()
wait=WebDriverWait(driver,20)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "aplazame-checkout-iframe")))
wait.until(EC.element_to_be_clickable((By.NAME,"accepts_gdpr"))).click()
You need to import below libraries
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
To come out from iframe use.
driver.switch_to.default_content()
try this
driver.find_element_by_name("accepts_gdpr").click()
Related
I have the following web page
.
I'm trying to double click the "Blocked_IPs" text.
This is the code that interacts with it:
blocked_ips = driver.find_elements_by_xpath('//td[contains(.,"Blocked_IPs")]')
print(len(blocked_ips), blocked_ips)
action = ActionChains(driver)
action.double_click(blocked_ips[0])
Problem is, it just doesn't seem to double click it. When I do it manually, it works. When I execute the code, it doesn't. There's only one occurance of the word "Blocked_IPs". This is the output in the terminal:
1 [<selenium.webdriver.remote.webelement.WebElement (session="82b277a5f85cbb202f5cd57c0b800f3b", element="530b1a15-a190-401c-8495-921777f8fa84")>]
Does anyone happen to know why it's not working? How can I test it? Thanks ahead!
You need to add perform() to make all the ActionChains happen as follows:
action.double_click(blocked_ips[0]).perform()
Ideally you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:
ActionChains(driver).double_click(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//td[contains(.,"Blocked_IPs")]")))).perform()
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
I am trying to click on the Apply button on linkedIn but, having a hard time in doing so. I tried to target the id but I noticed that the id always changes when the page reloads.
I've tried:
browser.find_element_by_xpath("//span[text() = 'Apply']").click() and browser.find_element_by_xpath("//button[#type = 'Apply']").click() but it doesn't work.
Use either of the xpath.
browser.find_element_by_xpath("//span[normalize-space(.)='Apply']").click()
OR
browser.find_element_by_xpath("//span[contains(.,'Apply')]").click()
UPADTE:
It seems synchronization issue induce WebDriverWait() and wait for element_to_be_clickable()
WebDriverWait(driver,15).until(EC.element_to_be_clickable((By.XPATH,"//span[normalize-space(.)='Apply']"))).click()
You need to import below libraries.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Selenium python return html with __VIEWSTATE.
I'm trying to open a page with selenium and perform the submit. However, the imput id has another name.
Is this a limitation of selenium or something on the page?
This is the page.
http://www8.receita.fazenda.gov.br/SimplesNacional/aplicacoes.aspx?id=21
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub',
desired_capabilities=DesiredCapabilities.CHROME)
driver.get("http://www8.receita.fazenda.gov.br/SimplesNacional/aplicacoes.aspx?id=22")
#driver.find_element_by_id("Cnpj").send_keys("99999999999")
#inputElement.send_keys('99999999999')
print(driver.page_source)
driver.quit()
The input element you are after is inside an iframe.You need to switch iframe first to access the input element.
Induce WebDriverWait() and wait for frame_to_be_available_and_switch_to_it()
Induce WebDriverWait() and wait for element_to_be_clickable()
Code:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver=webdriver.Chrome()
driver.get("http://www8.receita.fazenda.gov.br/SimplesNacional/aplicacoes.aspx?id=21")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"frame")))
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.ID,'Cnpj'))).send_keys("99999999999")
Browser snapshot
I am trying to click the follow button on Instagram using Python Selenium
https://www.instagram.com/luvly_zuby/?hl=en
I've tried the bellow code but it's not working.
#click follow
follow = driver.find_element_by_partial_link_text("Follo")
ActionChains(driver).move_to_element(follow).click().perform()
You can click on the element by using simple selenium click by finding the element using its text in the xpath and then using explicit wait on the element.
You can do it like:
follow_button = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//button[text()='Follow']")))
follow_button.click()
You need to add the following imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
This should work for you. Pass the WebElement to click(element) method.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('testUrl')
follow = driver.find_element(By.XPATH, '//button[contains(text(),'Follow')]')
webdriver.ActionChains(driver).move_to_element(follow).click(follow).perform()
Try to find the element using this css selector a.BY3EC > button and wait using .element_to_be_clickable:
follow = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'a.BY3EC > button')))
follow.click()
Following import:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
On the website the selenium script cannot find the login and password fields. I tried to search by xpath, css selector, name and class name. But nothing worked.
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get("https://login.aliexpress.com/")
driver.find_element_by_id("fm-login-id").send_keys("test_id")
driver.find_element_by_id("fm-login-password").clear()
driver.find_element_by_id("fm-login-password").send_keys("test_pass")
driver.find_element_by_id("fm-login-submit").click()`
I tried to do this with the help of Selenium IDE, and everything worked in the GUI. But after I exported the code to python and ran it, the program gave an error that it could not find the element.
The login form is inside of a frame, you need to switch to it first.
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get("https://login.aliexpress.com/")
frame = driver.find_element_by_id("alibaba-login-box")
driver.switch_to.frame(frame)
driver.find_element_by_id("fm-login-id").send_keys("test_id")
driver.find_element_by_id("fm-login-password").clear()
driver.find_element_by_id("fm-login-password").send_keys("test_pass")
driver.find_element_by_id("fm-login-submit").click()
However as the the desired elements are within an <iframe> so you have to:
Induce WebDriverWait for the desired frame to be available and switch to it.
Induce WebDriverWait for the desired elements to be clickable.
You can use the following solution:
Using CSS_SELECTOR:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("https://login.aliexpress.com/")
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#alibaba-login-box[src^='https://passport.aliexpress.com/mini_login.htm?']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.fm-text#fm-login-id"))).send_keys("test_id")
driver.find_element_by_css_selector("input.fm-text#fm-login-password").send_keys("test_pass")
driver.find_element_by_css_selector("input.fm-button#fm-login-submit").click()
Interim Broswer Snapshot:
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Reference
You can find a relevant discussion in
Ways to deal with #document under iframe