Hi can someone help me how can i accept the alert after I click the save button ?
I tried the accept.alert() but its not working
Try this with explicitly wait condition:
alert = WebDriverWait(driver, 30).until(
EC.alert_is_present())
alert.accept()
imports:
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
Related
I want to press a button with the XPath of
//*[#id="rass-action-proceed"]
i don't know how to use selenium. can someone help me please?
This will allow you to do so using the respective XPath:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
elem = driver.find_element_by_xpath('//a[#id="rass-action-proceed"]')
elem.click() # Using WebElements 'click()' method for sheer simplicity
You can try this :
driver.find_element_by_id("rass-action-proceed").click()
or with Explicit wait :
WebDriverWait(driver , 10).until(EC.element_to_be_clickable((By.ID, "rass-action-proceed"))).click()
make sure to import :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
So I have a problem.When I open Chrome with selenium and then I log in to an account.But in the upper right corner shows up an pop op if I will save the password.So how I can disable that?
The following code helps to dismiss the Alert
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
timeout = 5
WebDriverWait(driver, timeout).until(EC.alert_is_present())
alert = driver.switch_to.alert()
alert.dismiss()
I need to make a login script for the website https://cbdbene.com/
but when I try to send Keys to the email field, I get the error
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I have tried using,
login_email = browser.find_element_by_xpath("//input[#id='login_email']")
driver.execute_script("argument[0].setAttribute('value', 'abs#gmail.com');", login_email)
but that is also of no help,
Even clicking the element has no response,
login_email = browser.find_element_by_xpath("//input[#id='login_email']")
driver.execute_script("argument[0].click();", login_email)
I don't know how to fill this form. Can someone please explain me what am I doing wrong here ?
Try below solution :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome(executable_path=r"C:\New folder\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 50)
driver.get("https://cbdbene.com/")
warning = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[#class='modal-dismiss']//i//*[local-name()='svg']")))
driver.find_element_by_tag_name('body').send_keys("Keys.ESCAPE")
warning.click()
loginIcon = wait.until(EC.element_to_be_clickable((By.XPATH, "//li[3]//span[1]//div[1]//div[1]//*[local-name()='svg']")))
loginIcon.click()
inputBox = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[4]//div[1]//div[1]//div[1]//div[1]//div[1]//div[1]//div[1]//span[1]//input[1]")))
inputBox.send_keys("Username")
Output:
If you use absolute xpath you will see 3 inputs elements are there with same property.
Induce WebDriverWait() and element_to_be_clickable() and use valid xpath.samething you have do with password.
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
driver=webdriver.Chrome()
driver.get("https://cbdbene.com/")
WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.modal-dismiss"))).click()
WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"li.c-nav__list-item>span.c-nav__link"))).click()
WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"(//input[#id='login_email'])[last()]"))).click()
WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.XPATH,"(//input[#id='login_email'])[last()]"))).send_keys("user name")
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
Here is my code so far, note that the web page loads up with a captcha. I countered this with adding a time.sleep so I can run tests. When I try to submit the form by submitting "Create new account", I get an error saying the element has no attribute for 'submit'. I tried finding the element using xpath, css_selectos, tags, class names, etc.
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
browser = webdriver.Chrome()
browser.get('https://www.bstn.com/en/register/address')
time.sleep(35)
elam = browser.find_element_by_css_selector("[value='Create new account']")
elam.Submit()
If you are trying to click on Create new account button after filling information then please find below xpath to click on it
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[#class='button radius charcheck-submit']"))).click()
Another solution with action class
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver import ActionChains
actionChains = ActionChains(driver)
submit = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, "//input[#class='button radius charcheck-submit']")))
actionChains.move_to_element(submit).click().perform()
Working code
from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
browser = webdriver.Chrome(executable_path=r"C:\New folder\chromedriver.exe")
# browser = webdriver.Chrome()
browser.get('https://www.bstn.com/en/register/address')
time.sleep(35)
WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, "//input[#class='button radius charcheck-submit']"))).click()