how to press the "f_agreements_all" button ?
<label for="f_agreements_all">
<input type="checkbox" id="f_agreements_all">
<span></span>
<span class="permText">I accept all</span>
</label>
Unfortunately, finding "f_agreements_all" button and clicking it doesnt work. Span covers the whole button17x17px, when f_agreements_all is 16x16 under it. Do you know possible way to click it?
Using vanilla JS one way to do it would be:
const checkbox = document.getElementById('f_agreements_all');
checkbox.click();
Quickly looking at the Python Selenium 2 WebDriver API docs, one can try:
driver.find_element_by_id("f_agreements_all").click()
Can you please try below xpath :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
button=WebDriverWait(browser, 10).until(
EC.element_to_be_clickable((By.XPATH, "//li[#class='formCheckbox agreements all-agreements']//span[1]")))
button.click()
To click on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following solutions:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "label[for='f_agreements_all']"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//label[#for='f_agreements_all']"))).click()
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
Related
I'm trying to click on a button, but selenium can't find the element.
I'm using the xpath:
//button[#title="Monitor Chart(Ctrl+Alt+G)"]
but selenium can't locate. I can find the xpath from Chrome manualy using the find(Ctrl+F) tool, as we can see in the image.
Here is my code and error. The xpath does't have an ID.
Code Snapshot:
To click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.eui-btn.eui-btn-default.eui-btn-normal[title^='Monitor Chart']"))).click()
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[#class='eui-btn eui-btn-default eui-btn-normal' and starts-with(#title, 'Monitor Chart')]"))).click()
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.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
hiding_button = WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[title ='Monitor Chart(Ctrl+Alt+G)']")))
hiding_button.click()
Thanks to all. But I figure it out the issue. The button was inside an iFrame. So I hadd to switch to the iFrame first.
Code used:
iframe = driver.find_element_by_id('Access_Performance_Monitor')
driver.switch_to.frame(iframe)
I want to use selenium to login in the website https://www.winamax.es/account/login.php?redir=/apuestas-deportivas. The case is that I don't find the xpath/id/text to get te next code running successfully:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
options = webdriver.ChromeOptions()
options.add_argument("window-size=1920,1080")
options.add_argument('--disable-blink-features=AutomationControlled')
driver=webdriver.Chrome(options=options,executable_path=r"chromedriver.exe")
driver.get("https://www.winamax.es/account/login.php?redir=/apuestas-deportivas")
WebDriverWait(driver=driver, timeout=15).until(
lambda x: x.execute_script("return document.readyState === 'complete'")
)
upload_field = driver.find_element_by_xpath("//input[#type='email']")
I don't only want the specific xpath for this example, but I prefer a method to obtain the xpath or something similar to get the code working for other parts of the website
<iframe id="iframe-login" data-node="iframe" name="login" scrolling="auto" frameborder="1" style="min-height: 280px; width: 100%;"></iframe>
Your element is in an iframe. Switch to it.
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "iframe-login")))
Import
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Full working code.
wait = WebDriverWait(driver, 10)
driver.get("https://www.winamax.es/account/login.php?redir=/apuestas-deportivas")
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "iframe-login")))
upload_field = wait.until(EC.element_to_be_clickable((By.XPATH, "//input[#type='email']")))
upload_field.send_keys("stuff")
The email element is 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 element to be clickable.
You can use either of the following Locator Strategies:
Using CSS_SELECTOR:
driver.get("https://www.winamax.es/account/login.php?redir=/apuestas-deportivas")
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#iframe-login")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='email']"))).send_keys("scraper#stackoverflow.com")
Using XPATH:
driver.get("https://www.winamax.es/account/login.php?redir=/apuestas-deportivas")
WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[#id='iframe-login']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#type='email']"))).send_keys("scraper#stackoverflow.com")
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
Browser Snapshot:
Reference
You can find a couple of relevant discussions in:
Ways to deal with #document under iframe
Switch to an iframe through Selenium and python
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element while trying to click Next button with selenium
selenium in python : NoSuchElementException: Message: no such element: Unable to locate element
I'm developing test automation and I want to click on element located in toolbar,I'm using python and selenium. Here is a code of website
<dl class="ToolbarDropdown_menu_2wY9X ToolbarDropdown_isHidden_3UaGr" tabindex="0" style=""
xpath="1"><dt><span class="ToolbarDropdown_title_1NBVn">New</span>
<span class="DropdownArrow_arrowIcon_dDzph DropdownArrow_down_3dlvo"></span>
</dt>
<dd class="ToolbarDropdown_item_nP-_M" style="">Dataset</dd>
<dd class="ToolbarDropdown_item_nP-_M">Project</dd>
</dl>
I need to click on element with text Dataset.
I locate element in this way
DATASET_BUTTON = (By.XPATH, '//dd[contains(text(),"Dataset")]')
And I want to perform action like that
self.driver.find_element(*VideosPageLocator.DATASET_BUTTON).click()
And there is no action but in terminal looks like my step has passed. Do you have any idea how to click on element in dropdown?
Maybe the action is done before DOM has loaded completely.
Try using WebDriverWait.
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
web_driver_wait = WebDriverWait(self.driver, 10)
element = web_driver_wait.until(EC.element_to_be_clickable((By.XPATH,'//dd[contains(text(),"Dataset")]')))
element.click()
To invoke click() on the element with text as Dataset you have to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:
Using XPATH:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//dl[starts-with(#class, 'ToolbarDropdown')]//dd[starts-with(#class, 'ToolbarDropdown_item') and text()='Dataset']"))).click()
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
trying to click a input type using selenium python, input type calls image file, and added css cursor: pointer on the image, unfortunately cant click the image or the input
Image
Code
<input type="image" src="/images/btn_next.png">
CSS
input[type="image" i]
{
cursor: pointer;
}
how to click on the image "Next Step" ?
I tried, but shows error
driver.find_element_by_xpath('//input[#type="image"][#src="/images/btn_next.png"]').click()
Try Use WebdriverWait and element_to_be_clickable to click on the image.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH,'//input[#type="image"][#src="/images/btn_next.png"]'))).click()
If above code unable to click on the element try use javaScript executor to click on the element.
driver.execute_script("arguments[0].click();",driver.find_element_by_xpath('//input[#type="image"][#src="/images/btn_next.png"]'))
You were close. To click() on the element you need to club up the attributes within the xpath using and and you can use either of the following Locator Strategies:
Using css_selector:
driver.find_element_by_css_selector("input[src='/images/btn_next.png'][type='image']").click()
Using xpath:
driver.find_element_by_xpath("//input[#src='/images/btn_next.png' and #type='image']").click()
But as you intend to invoke click() on the element, ideally you need to induce WebDriverWait for the element_to_be_clickable() as follows:
Using css_selector:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[src='/images/btn_next.png'][type='image']"))).click()
Using xpath:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[#src='/images/btn_next.png' and #type='image']"))).click()
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
If you run chrome then probably moving physical cursor to image and click can help. There is python package that move physical cursor to web element, selenium-move-cursor.
I have a problem, I happen to have a button with these labels, I'm trying to click through Selenium but I can not find a way to click it. I tried to give it taking as reference the XPath, link text, and CSS selector but I do not achieve my goal. This is the code for the button:
<a class="btn btn-flat pull-right" data-action="export_report"> <i class = "icon-export"> </ i> Export </a>
East of the XPath:
// * [# id = "reports"] / div [1] / div [2] / a
this selector:
#reports> div.span12> div.headline-action-block.pull-right> a
This is the button and my code in Python :(
Button:
My code:
I face this error:
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 955, in find_element
'value': value})['value']
You can try this:
openrate = driver.find_element_by_css_selector("a.btn")
openrate.click()
Assuming this is the only button, or the first button on the page. Otherwise ("a.btn.btn-flat.pull-right")
As per the HTML you have shared it seems you have invoked click() in the previous step so in this step to click() on the button with text as Export you have to induce WebDriverwait for the element to be clickable and you can use either of the following Locator Strategies :
PARTIAL_LINK_TEXT :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
# lines of code
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.PARTIAL_LINK_TEXT, "Export"))).click()
CSS_SELECTOR :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
# lines of code
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-flat.pull-right[data-action='export_report']>i.icon-export"))).click()
XPATH :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
# lines of code
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[#class='btn btn-flat pull-right' and #data-action='export_report']/i[#class='icon-export']"))).click()