I have an issue when trying to click this button in Selinium:
The folloying is the html code for each side:
"plus de 26 ans"
"Moins de 26 ans"
I have tride creating a button clicker by id using selenium (for first button):
btn_date = driver.find_element_by_id("radio-ins_age-above_26")
btn_date.click()
I get the error message that it is not clickable.
However, when viewing the html when I switch from one button to other I get the following change:
First button:
There is "::after::" that appears. When I click or press anything else it disappears.
How can I click this button?
Thanks
To click on dynamic element use WebDriverWait() and wait for element to be clickable.
Use the following xpath to click.
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//span[contains(.,'Plus de 26')]"))).click()
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//span[contains(.,'Moins de 26')]"))).click()
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
Related
I am Trying to create a bot that can fill a cart with these beer bottles. I really want to do this on a few different sites but for some reason i can only get it to open the page and click the first button, then it doesn't click the next button. I tried ID, Name, pretty much anyway to identify the button but it won't click it. I even tried sleep for 3 seconds. I tried to see if it was in an Iframe but i don't think it is. I'm out of ideas.... Link is https://www.sideprojectbrewing.com/shop?category=Beer+Release
I'm trying to access the add to cart element but does not seem to work
\
from Config import keys
from selenium import webdriver
def order(k):
driver = webdriver.Chrome(executable_path=r"C:\Users\ezliv\Desktop\ShopBot1\chromedriver_win32\chromedriver.exe")
driver.get(k['product_url'])
driver.find_element_by_xpath('//*[#id="thumb-biereblanche"]/div/div[1]/div/div/img').click()
driver.find_element_by_xpath('//*[#id="yui_3_17_2_1_1606181545139_755"]').click()
\\
You can try following code:
driver.get(url_here)
wait = WebDriverWait(driver, 20)
bottle = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[#id="thumb-biereblanche"]/div/div[1]/div/div/img')))
bottle.click()
add_to_cart = wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'sqs-add-to-cart-button-inner')))
add_to_cart.click()
Import:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
I've created a script in python using selenium to click on a like button available in a webpage. I've used xpath in order to locate that button and I think I've used it correctly. However, the script doesn't seem to find that button and as a results it throws TimeoutException error pointing at the very line containing the xpath.
As it is not possible to hit that like button without logging in, I expect the script to get the relevant html connected to that button so that I understand I could locate it correctly.
I've tried with:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
link = "https://www.instagram.com/p/CBi_eIuAwbG/"
with webdriver.Chrome() as driver:
wait = WebDriverWait(driver,10)
driver.get(link)
item = wait.until(EC.visibility_of_element_located((By.XPATH,"//button[./svg[#aria-label='Like']]")))
print(item.get_attribute("innerHTML"))
How can I locate that like button visible as heart symbol using selenium?
To click on Like Button induce WebDriverWait() and wait for visibility_of_element_located() and below xpath.
Then scroll the element into view and click.
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.get("https://www.instagram.com/p/CBi_eIuAwbG/")
element=WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,"//button[.//*[name()='svg' and #aria-label='Like']]")))
element.location_once_scrolled_into_view
element.click()
You can do it like this
likeSVG = driver.find_element(By.CSS_SELECTOR, 'svg[aria-label="Like"]')
likeBtn = likeSVG.find_element(By.XPATH, './..')
likeBtn.click()
likeBtn is equal to the parent of the likeSVG div as you can use XPATH similar to file navigation commands in a CLI.
Try using the .find_element_by_xpath(xPath) method (Uses full xpath):
likeXPATH = "/html/body/div[1]/section/main/div/div[1]/article/div[2]/section[1]/span[1]/button"
likeElement = driver.find_element_by_xpath(likeXPATH)
likeElement.click()
I want to click the "OK" button in this pop up dialog
I tried:
driver.switchTo().alert().accept();
but it doesn't work
To click on the OK button within the alert you need to induce WebDriverWait for the desired alert_is_present() and you can use the following solution:
WebDriverWait(driver, 10).until(EC.alert_is_present())
driver.switch_to.alert.accept()
Note : You have to add the following imports :
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Reference
You can find a couple of relevant discussions in:
Python click button on alert
How to read the text from the alert box using Python + Selenium
Why switching to alert through selenium is not stable?
Would like to understand why switch_to_alert() is receiving a strikethrough and how to fix
I'd like to close this window opened up on Amazon web site by using Selenium with Python. I've tried find_element_by_xpath, but it doesn't work. Here's the snippet of the code;
close_to_list = browser.get("/html/body/div[4]/div/div/div[2]/div[2]/div[2]/div[1]/div[2]/div/div/table/tbody/tr[2]")
I get the xpath of that 'X' button but I guess I need to close it as switch_to_alert, but I'm new to this era so I couldn't write it properly.
Here's the image view;
enter image description here
You don't need to use switch_to_alert() as well as get() to close modal window. Just try to close it with below code:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'button[aria-label="Close"]'))).click()
This allows you to wait for button appearance and click the button
I want to control webpage with selenium and python
Python code;
menu = browser.find_element_by_css_selector(".nav")
hidden = browser.find_element_by_link_text('Soluton')
element = browser.find_element_by_xpath("//div[#class=\"two-columns\"]")
Option 1: ActionChains(browser).move_to_element(menu).click(hidden)
Option 2 : ActionChains(browser).move_to_element(element).click(hidden)
html code;
I want to click "Solution" button under the nav menu.
However, Solution be in under the nav menu. So it's hidden.
so, I type following codes ;
Option 1:
ActionChains(browser).move_to_element(menu).click(hidden)
Option 2 :
ActionChains(browser).move_to_element(element).click(hidden)
But selenium not happen anything and not give any error message.
How can I click a button under nav menu with selenium ?
Thanks
If I have understood your Question and your Requirement we need to Mouse Hover over the WebElement with text as Actions where 2 options pops out as Request and Solution and you want to click() on Solution. To achieve that you can use the following code block :
#import
from selenium.webdriver.common.action_chains import ActionChains
#code block
menu = driver.find_element_by_xpath("//a[#class='incident-action']/i[#class='icon-ellipsis-h']")
ActionChains(driver).move_to_element(menu).perform()
driver.find_element_by_xpath("//div[#class='action-list' and #id='header-actions-list']//a[#class='icon-arrow' and contains(text(),'Solution')]").click()
You can try to click Actions to make actions list visible and then click on required Solution option:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
actions = wait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Actions")))
actions.click()
solution = wait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Solution")))
solution.click()