The problem is when I am clicking the first name field, the click is working, but when I am sending the text to the field, it is showing me the error:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
Here is my code:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys
s = Service("C:/Users/TUL/Desktop/cd/cd.exe")
driver = webdriver.Chrome(service=s)
driver.get('https://www.universityliving.com/')
driver.maximize_window()
time.sleep(3)
driver.find_element(By.XPATH, '/html/body/div[3]/div/div/div[2]/button').click()
time.sleep(1)
driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/div[3]/div/div/a[1]/div/div/div').click()
time.sleep(2)
driver.switch_to.window(driver.window_handles[1])
driver.find_element(By.XPATH, "//div[#class='slick-slide slick-active slick-current']//div//img[#alt='Urbanest Carlton Melbourne']").click()
time.sleep(2)
driver.switch_to.window(driver.window_handles[2])
driver.find_element(By.XPATH, '/html/body/div[2]/div/div[2]/div[3]/div[2]/div/div[2]/div/div[3]/div/div/div[3]/div/div[3]/div/ul/li[2]/p').click()
driver.current_window_handle
driver.find_element(By.XPATH, '//*[#id="enquiryForm"]/div[1]/div[1]/div/div/label').click()
driver.find_element(By.XPATH, '//*[#id="enquiryForm"]/div[1]/div[1]/div/div/label').send_keys('h')
time.sleep(3)
What I am expecting is, if the field is clickable then it must be text acceptable also.
Related
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome('ChromeDriver')
driver.get("https://devbusiness.tunai.io/login")
time.sleep(2)
driver.maximize_window()
#log in credentials
username = driver.find_element(By.NAME, "loginUsername");
username.send_keys("kevin#tunai");
password = driver.find_element(By.NAME, "loginPassword");
password.send_keys("xxxxx");
login = driver.find_element(By.XPATH,"//*[#id='app']/div/div/div/div/div/div[2]/form/div[4]/button");
login.submit();
time.sleep(3)
driver.get("https://devbusiness.tunai.io/dashboard/salon_report_voucher")
time.sleep(3)
driver.find_element(By.XPATH, '//*[#id="packageTable"]/tbody[1]/tr/td[1]').click()
time.sleep(2)
driver.find_element(By.XPATH,'//*[#id="packageTable"]/tbody[1]/tr').click()
time.sleep(2)
#trigger the element before click
voucher = driver.find_element(By.XPATH, "//*[#id='packageTable']/tbody[2]/tr[1]")
driver.execute_script("arguments[0].click();", voucher)
time.sleep(2)
driver.find_element(By.XPATH, '//*[#id="packageTable"]/tbody[2]/tr[1]')
time.sleep(2)
#trigger the detail button
detail = driver.find_element(By.XPATH, "//*[#id='checkAll']")
driver.execute_script("arguments[0].click();", detail)
time.sleep(5)
driver.find_element(By.XPATH, "//*[#id='checkAll']")
time.sleep(5)
driver.find_element(By.XPATH, '//*[#id="voucherModal___BV_modal_body_"]/div/div/button[1]').click()
time.sleep(5)
I wanna click on the edit new price and enter a new price, save it and loop it. For now, I am not allow to enter the new price and proceed. I copied the Xpath and tried, but it failed so i m thinking because of the popout page. thats why it failed.
To click on Edit Price button. use webdriverwait() and wait for element to be clickable and following xpath.
Then wait for model to pop up and then enter the value.
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[#id='voucherModal___BV_modal_content_']//button[text()='Edit Price']"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[#id='voucherEditModal___BV_modal_content_']//input[#data-maska-tokens]"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[#id='voucherEditModal___BV_modal_content_']//input[#data-maska-tokens]"))).send_keys("1000")
you need to import below libraries.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
I'm trying to use Selenium to click on "show more" under "about this show" on this URL:
https://www.bandsintown.com/e/1024477910-hot-8-brass-band-at-the-howlin'-wolf?came_from=253&utm_medium=web&utm_source=city_page&utm_campaign=event
Here's my code:
#Get Event Info - expand 'read more'
try:
time.sleep(3)
readMoreEvent = driver.find_element_by_xpath("//div[#class='xXGKBimvIBU_aEdJh3EF']").click();
print("More Event Info Clicked")
except (ElementNotVisibleException, NoSuchElementException, TimeoutException):
pass
I'm getting an error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted:
.</div> is not clickable at point (477, 9). Other element would receive the click:
Here's a photo of the div I'm trying to click:
So, it seems like something is blocking the page-click. How can I solve this issue?
I saw that there's a dialogue box that pops up which asks user to login. That could be interrupting the click.
A better approach is to:
Wait until the link is clickable
Capture the exception and use an alternative method to click on the link
This should work:
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
from selenium.common.exceptions import ElementClickInterceptedException
from selenium.webdriver.chrome.options import Options
from time import sleep
options = Options()
options.add_argument("--disable-notifications")
driver = webdriver.Chrome(executable_path='D://chromedriver/100/chromedriver.exe', options=options)
wait = WebDriverWait(driver, 20)
url = "https://www.bandsintown.com/e/1024477910-hot-8-brass-band-at-the-howlin%27-wolf?came_from=253&utm_medium=web&utm_source=city_page&utm_campaign=event"
driver.get(url)
try:
showmore_link = wait.until(EC.element_to_be_clickable((By.XPATH, '//div[#class="xXGKBimvIBU_aEdJh3EF"]')))
showmore_link.click()
except ElementClickInterceptedException:
print("Trying to click on the button again")
driver.execute_script("arguments[0].click()", showmore_link)
I am trying to do a tutorial and learn Selenium in python however i cant seem to get Selenium to enter the postcode into the psotcode field/form box.=
I am using:
Python v3.9
Chrome v87
This is the URL i am practicing on:
https://www.currys.co.uk/app/checkout
And this is my current code:
# Selenium Tutorial #1
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
# Open Chromedriver
driver = webdriver.Chrome(r"C:\Users\Ste1337\Desktop\chromedriver\chromedriver.exe")
# Open webpage
driver.get("https://www.currys.co.uk/gbuk/tv-and-home-entertainment/televisions/televisions/samsung-ue75tu7020kxxu-75-smart-4k-ultra-hd-hdr-led-tv-10213562-pdt.html")
# Click "Accept All Cookies" or ignore if no pop up
try:
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "onetrust-accept-btn-handler")))
element.click()
except Exception:
pass
# Wait 3 seconds
driver.implicitly_wait(3)
# Click "Add to Basket" or refresh page if out of stock
try:
element = WebDriverWait(driver, 1).until(EC.presence_of_element_located((By.XPATH, "email-desktop")))
time.sleep(5)
browser.refresh()
except:
button = driver.find_element_by_css_selector("button.Button__StyledButton-bvTPUF.hZIOeU.Button-jyKNMA.GZkwS")
driver.execute_script("arguments[0].click();", button)
# Wait 3 seconds
driver.implicitly_wait(3)
# Click "Continue to Basket"
button = driver.find_element_by_css_selector("button.Button__StyledButton-bvTPUF.hZIOeU.Button-jyKNMA.sc-fzpjYC.gJohPa")
driver.execute_script("arguments[0].click();", button)
# Wait 3 seconds
driver.implicitly_wait(3)
# Click "Go to checkout"
button = driver.find_element_by_xpath("//button[contains(#data-component, 'Button')][contains(#type, 'button')]")
driver.execute_script("arguments[0].click();", button)
# Type in postcode
search=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//input[#contains='Postcode Checker")))
search.send_keys("NG229NU")
search.send_keys(Keys.RETURN)
your locator is wrong for search , use:
search = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//input[#aria-label="Postcode Checker"]')))
I'm working to automate web page where i'm unable to close the pop up. I have tried to refresh/switch to pop up window, nothing worked.
Code:
from selenium import webdriver
import time
driver = webdriver.Chrome(executable_path='F:\chromedriver_win32\chromedriver.exe')
driver.get('https://www.libertymutual.com/get-a-quote')
driver.maximize_window()
driver.find_element_by_xpath(
'//*[#id="1555468516747"]/section/div[2]/section/form/div[1]/div[3]/div/div[1]').click()
time.sleep(1)
driver.find_element_by_xpath('//*[#id="zipcode-1555468516747-1555468516747"]').click()
driver.find_element_by_xpath('//*[#id="zipcode-1555468516747-1555468516747"]').send_keys('03878')
time.sleep(1)
driver.find_element_by_xpath(
'//*[#id="1555468516747"]/section/div[2]/section/form/div[2]/div[5]/div/div/button').submit()
time.sleep(5)
x=driver.find_element_by_xpath('//*[#id="discount-marketing-modal"]/header/button/svg').click()
driver.refresh()
If you want directly go to web page, https://buy.libertymutual.com/auto?city=Somersworth&jurisdiction=NH&lob=Auto&policyType=Auto&zipCode=03878
Replace last 3 lines of your code by below lines.Used action chain to click.
time.sleep(5)
ok = driver.find_element_by_xpath('//*[#id="discount-marketing-modal"]/footer/button')
ActionChains(driver).move_to_element(ok).pause(1).click(ok).perform()
x=driver.find_element_by_xpath('//*[#id="discount-marketing-modal"]/header/button/svg').click()
This is css selector for popup close button : .lm-Icon.lm-Icon-Close
But this element can't use the .click() method, the .click() method will produce this error:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted:
Use ActionChains to solve this problem.
You can try the following code:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver import ActionChains
driver = webdriver.Chrome(executable_path='F:\chromedriver_win32\chromedriver.exe')
driver.get('https://www.libertymutual.com/get-a-quote')
driver.maximize_window()
wait = WebDriverWait(driver, 20)
auto_element = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[#class='quotingText']//span[contains(text(), 'Auto')]")))
auto_element.click()
zip_code = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.zipcode")))
zip_code.click()
zip_code.send_keys("03878")
driver.find_element_by_css_selector('div.buttonWrapper button').submit()
popup_close_btn = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".lm-Icon.lm-Icon-Close")))
action = ActionChains(driver)
action.move_to_element(popup_close_btn).click(popup_close_btn).perform()
WebDriverWait better than time.sleep(..)
hi there i need some help with the following code ....
i`m using selenium with python to send tweets automatically :
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path = r'C:/webDriver/chromedriver.exe')
driver.get("https://twitter.com/login")
username = driver.find_element_by_css_selector("input[placeholder='Phone, email or username']")
password= driver.find_element_by_css_selector("input[class='js-password-field']")
username.send_keys("xxxx")
password.send_keys("xxxx")
submit = driver.find_element_by_xpath("//button[text()='Log in']")
submit.click()
time.sleep(2.4)
autotw1 = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, '//*[#id="tweet-box-home-timeline"]/div'))).click
autotw1.send_keys("""testing """)
time.sleep(5)
tweet = driver.find_element_by_xpath('//span[#class="add-tweet-button "]//following-sibling::button[contains(#class,"tweet-action")]')
tweet.click()
But It gave me error :
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
i think the error came from xpath cause of the twitter website new style !!
You can use this locator:By.CLASS_NAME, 'DraftEditor-root'.
You must click on the element to bring up other elements to write the tweet, which is:By.CLASS_NAME, 'public-DraftEditorPlaceholder-root'), and use ActionChains to send text.
Following import:
from selenium.webdriver import ActionChains
Try the bellow code:
#submit login
submit = driver.find_element_by_xpath("//button[text()='Log in']")
submit.click()
autotw1 = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, 'DraftEditor-root')))
autotw1.click()
element = WebDriverWait(driver, 3).until(EC.element_to_be_clickable((By.CLASS_NAME, 'public-DraftEditorPlaceholder-root')))
ActionChains(driver).move_to_element(element).send_keys('testing').perform()
sendTw = WebDriverWait(driver, 3).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Tweet')))
sendTw.click()