Path here
I need to press the button but cant really figure out how
I tried copying the xpath but get an error
also tried to press the button over the id or class_name but also not worked
If you have an idea please write it in the comments. Thanks
Tried so far:
driver.find_element_by_xpath("//button[#class='action-button']").click()
driver.find_element_by_class_name("action-button").click()
driver.find_element_by_xpath("[#id='clearBrowsingDataConfirm']").click()
driver.find_element_by_id('[#id="clearBrowsingDataConfirm"]').click()
Should work if it's not in a iframe.
driver.find_element_by_id('clearBrowsingDataConfirm').click()
Try this if it's after driver.get()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'clearBrowsingDataConfirm'))).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
Related
I am writing a code that will hopefully be able to click on a defined button on a pop-up window. The pop-up window appears only after having clicked somewhere else (this part is working).
here's the code:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
wait = WebDriverWait(driver, 2)
wait.until(EC.element_to_be_clickable((By.XPATH, '//button\[text()="OK"\]')))
wait.until(ExpectedConditions.visibilityOfElementLocated(By.XPATH, '//button\[text()="OK"\]'))
wait.until(ExpectedConditions.elementToBeClickable(By.XPATH, '//button\[text()="OK"\]'))
driver.findElement(By.XPATH, '//button\[text()="OK"\]').click()
I am getting an error "TimeoutException". Anyone able to fix that?
thanks a lot
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
I have this piece of code which works as it is:
time.sleep(0.7)
self.driver.find_element_by_xpath("anyXpath").click()
I make the program to wait for a time so the button on the pop-up window is really there to be clicked, and this solution works.
Now, I want to do the same but with WEbDriverWait and I wrote this:
WebDriverWait(self.driver,10).until(expected_conditions.presence_of_element_located(By.XPATH, "anyXpath"))
self.driver.find_element_by_xpath("anyXpath").click()
But the button is never clicked. What am I doing wrong? I am open to use another expected condition different from presence_of_element_located but I guess it should work with the latter also.
Thanks.
By importing WebDriverWait, expected_conditions, and By, you can wait until the WebDriver deems an element clickable before it clicks the element.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.ui import WebDriverWait
WebDriverWait(10, self.driver).until(
expected_conditions.element_to_be_clickable(
(By.XPATH, "//xpath//to//element")
)
).click()
Make sure that you pass a tuple to element_to_be_clickable().
You can try this method. It wait for element to be click able
WebDriverWait(10, driver).until(EC.element_to_be_clickable(By.XPATH, "anyXpath"))
import
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
I'm trying to create a macro that opens up all my online classes on Chrome (cause logging in is annoying, especially if you have to do it 8 times every morning).
BTW, I use Python 3.8, Chrome 81.0.4044.122, and the latest version of Selenium.
Until now, I clicked button using:
driver = webdriver.Chrome()
driver.find_element_by_xpath("PATH_OF_ELEMENT").click()
And then I find a login button that has a image instead of text.
I tried XPath, CSS Selector, id, name, the link of text, ActionChains (move_to) nothing works.
Here's the HTML:
here click me please.
The button I'm trying to press is the one with the tag a.
I spent 30 minutes googling about this and all I found was Stack Overflow questions from 6 years ago. They suggested I use WebDriverWait or change the frame. None of them worked (I might have made a mistake). I'm new to Selenium so please be kind and explain hard stuff.
How can I find the correct XPath of an image button and click it?
driver.find_element_by_css_selector('.nice-select').click()
driver.find_element_by_xpath("/html/body/div1/div[3]/div/div/div/div/div/div2/div1/div/ul/li2").click()
driver.find_element_by_xpath('/html/body/div1/div[3]/div/div/div/div/div/div2/div2/div/span').click()
driver.find_element_by_xpath('/html/body/div1/div[3]/div/div/div/div/div/div2/div2/div/ul/li[19]').click()
driver.find_element_by_xpath('/html/body/div1/div[3]/div/div/div/div/div/div2/div[3]/div/span').click()
driver.find_element_by_xpath('/html/body/div1/div[3]/div/div/div/div/div/div2/div[3]/div/ul/li[3]').click()
driver.find_element_by_xpath('/html/body/div1/div[3]/div/div/div/div/div/div2/div[4]/div/span').click()
driver.find_element_by_xpath('/html/body/div1/div[3]/div/div/div/div/div/div2/div[4]/div/ul/li[3]').click()
driver.find_element_by_xpath('/html/body/div1/div[3]/div/div/div/div/div/div2/div[5]/a').click()
Try the following CSS Selector:
.my_menu>a
Code should look like:
driver.find_element_by_css_selector(".my_menu>a").click()
Also, try to locate the element with explicit wait:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".my_menu>a"))).click()
I have tested with the following code block (as result will be displayed popup with 2 options):
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
import time
driver = webdriver.Chrome()
driver.get("https://oc31.ebssw.kr/onlineClass/search/onlineClassSearchView.do?schulCcode=00898&schCssTyp=online_mid")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, ".my_menu>a"))).click()
time.sleep(5)
I hope it helps you!
I tried to close a cookie button on whoscored.com, I located the button, however when the program clicks, it seems to click the ad behind the button, and it ends up opening a new page instead of closing the cookie button. Any idea of what I can do?
url='https://www.whoscored.com/Search/?t=Crystal+Palace'
browse=webdriver.Chrome()
browse.get(url)
time.sleep(4)
cacheButton=browse.find_elements_by_xpath('//button')
cacheButton[1].click() #This is the "I ACCEPT" button.
Here is the html for the button:
<button class="qc-cmp-button" onclick="window.__cmpui("setAndSaveAllConsent",!0)"> I accept </button>
Would appreciate if anyone can help me.
Induce WebDriverWait() and wait for element_to_be_clickable() and following xpath.
WebDriverWait(browse,15).until(EC.element_to_be_clickable((By.XPATH,"//button[#class='qc-cmp-button' and contains(.,'I accept')]"))).click()
Add following libraries.
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Code:
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
url='https://www.whoscored.com/Search/?t=Crystal+Palace'
browse=webdriver.Chrome()
browse.get(url)
WebDriverWait(browse,15).until(EC.element_to_be_clickable((By.XPATH,"//button[#class='qc-cmp-button' and contains(.,'I accept')]"))).click()
Browser sanpshot:
Update:
cookie=btn=WebDriverWait(browse,15).until(EC.presence_of_element_located((By.XPATH,"//button[#class='qc-cmp-button' and contains(.,'I accept')]")))
browse.execute_script("arguments[0].click();", cookie)