I am trying to click a button with selenium webdriver. But not managing to identify the button.
This is my code: It returns an error message
NoSuchElementException: Message: u'no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="artifactContentList"]/div[2]/div/div[3]/content-dataset-actions/content-dataset-actions/section/section/button[2]"}\n (Session info: headless chrome=81.0.4044.138)\n (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.18363 x86_64)'
from selenium.webdriver.chrome.options import Options
from splinter import Browser
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import csv
chrome_options = Options()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(executable_path= "C:\chromedriver\chromedriver.exe", chrome_options=chrome_options)
def open_url():
browser = webdriver.Chrome(executable_path= "C:\chromedriver\chromedriver.exe", chrome_options=chrome_options)
browser.get("https://app.powerbi.com/groups/xxxxs")
python_button = browser.find_element_by_xpath('/html/body/div[1]/root-downgrade/mat-sidenav-container/mat-sidenav-content/div/landing/div/div/div/ng-transclude/landing-route/list-proxy/content-list/div/main/dataset-list/div/virtual-scroll/div[2]/div/div[3]/content-dataset-actions/content-dataset-actions/section/section/button[2]')
print(python_button)
python_button.click()
browser.quit()
open_url()
This is the full element:
<button class="refreshNow pbi-glyph pbi-glyph-refresh" localize-tooltip="RefreshNow" ng-if="::$ctrl.canRefreshNow" ng-click="$ctrl.runAction($ctrl.RefreshNow)" aria-describedby="ModeldatasetMenu4" use-tooltip-as-aria-label="" title="Refresh now" aria-label="Refresh now" pbi-focus-tracker-idx="54"></button>
Try this:
python_button = browser.find_element_by_class_name('refreshNow')
Related
I tried to launch chrome with selenium. but as soon as the browser loads the urls, google chrome closes automatically. here is the code:
'''
from selenium import webdriver
url= 'https://www.gmail.com'
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(url)
'''
Because selenium4 no need to use driver.close()
method they automatically close the driver after execution. So options.add_experimental_option("detach", True) argument will help you to prevent to close immediately after once launch the url with google chrome
# selenium 4
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
#chrome to stay open
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
url= 'https://www.gmail.com'
driver.get(url)
time.sleep(2)
Been searching for a while and tried all the solutions present but none appear to be working. I created a "slide show" that will first log in, then alternate between tabs. All of that is working but i cannot get rid of the
"Chrome is being controlled by automated test software" bar. Any advise?
Code
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
usernameStr = 'test'
passwordStr = 'test'
browser = webdriver.Chrome()
#first tab
browser.get(('www.testwebsite.com?'))
# fill in username and hit the next button
username = browser.find_element_by_id('username')
username.send_keys(usernameStr)
password = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, 'password')))
password.send_keys(passwordStr)
nextButton = browser.find_element_by_class_name('emp-submit')
nextButton.click()
#second tab
browser.execute_script("window.open('about:blank', 'tab2');")
browser.switch_to.window("tab2")
browser.get('www.testwebsite.com')
Try this:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option("excludeSwitches",["enable-automation"])
driver_path = '/Users/myuser/Downloads/chromedriver'
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=options)
driver.get('https://google.com')
driver.close()
When you open Chrome Browser in through ChromeDriver this infobar containing the notification is embedded as follows:
Chrome is being controlled by automated test software
Browser snapshot without the argument disable-infobars:
But if you add the argument disable-infobars through an instance of ChromeOptions you can get rid of this infobar as follows:
Code Block:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://www.google.com/')
Browser snapshot applying the argument disable-infobars:
THIS IS WORKING WITH LATEST RELEASE.
Try it by changing driver path under "service_obj"
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches",["enable-automation"])
service_obj = Service(r"C:\Users\Documents\Sublime_srk\drivers\chromedriver_win32\chromedriver.exe")
driver = webdriver.Chrome(options=chrome_options,service=service_obj)
driver.get("https://www.google.co.in/")
Click on the "x" to close the bar. It doesn't work initially, but then maximize and restore the window and it should disappear. This is for anyone who doesn't trigger their tests through Java.
I have using python selenium to do some test but I don't want it to open any browser, so how I can use a headless browser?? can you guys help me :((
Here is my code:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome('/Users/toanhac/Downloads/chromedriver')
url = 'https://mail.google.com/mail/u/0/#inbox'
driver.get(url)
driver.implicitly_wait(15)
driver.find_element_by_id("identifierId").send_keys(mail)
driver.find_element_by_id("identifierNext").click()
driver.find_element_by_name("password").send_keys(password)
driver.find_element_by_id("passwordNext").click()
Just set headless to True:
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True
Full code:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True
driver = webdriver.Chrome('/Users/toanhac/Downloads/chromedriver', options=options)
url = 'https://mail.google.com/mail/u/0/#inbox'
driver.get(url)
driver.implicitly_wait(15)
driver.find_element_by_id("identifierId").send_keys(mail)
driver.find_element_by_id("identifierNext").click()
driver.find_element_by_name("password").send_keys(password)
driver.find_element_by_id("passwordNext").click()
Info
I want to automate the web-server http://bioinfo.unipune.ac.in/IRESPred/IRESPred.html using python selenium.
html code
<input name="fileToUpload" type="file" class="btn btn-default btn-file btn-sm" xpath="1">
code
from selenium import webdriver
import time
driver = webdriver.Edge(r"C:\Users\Amardeep\Downloads\msedgedriver.exe")
driver.maximize_window()
driver.get("http://bioinfo.unipune.ac.in/IRESPred/IRESPred.html")
time.sleep(2)
button = driver.find_element_by_xpath("//input[#name = 'fileToUpload']").click()
output error
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument
Tried solutions
I used different x-paths to click the button which opens a window to upload a file-path but button is not clickable. I used find element by name,class name,css selector but it also not worked. How should I solve this problem.
Try below code - (I'm using Chromedriver and you are using Edge, so modify code accordingly)
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 5)
action = ActionChains(driver)
driver.get("http://bioinfo.unipune.ac.in/IRESPred/IRESPred.html")
time.sleep(2)
Upload_btn = wait.until(EC.presence_of_element_located((By.XPATH, "//input[#name='fileToUpload']")))
action.move_to_element(Upload_btn).click().perform()
I'm able to click on a button using the above code, let me know if you have any issues or you face any error message.
I am writing a selenium test case to automate surveymonkey.
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("-incognito --no-sandbox")
driver = webdriver.Chrome(executable_path='/usr/lib64/chromium/chromedriver', chrome_options=chrome_options)
driver.get('https://www.surveymonkey.com/r/WXNXWVB')
time.sleep(3)
vote_check = driver.find_element_by_id('96247410_725897453')
vote_check.click()
time.sleep(3)
nxt_btn = driver.find_element_by_name('Done')
nxt_btn.click()
driver.quit()
And I get the flowing error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <input id="96247410_725897453" name="96247410" type="radio" class="radio-button-input" value="725897453"> is not clickable at point (850, 203). Other element would receive the click: <span class="radio-button-display ">...</span>
What am I doing wrong?
Please Find the Below Workable code:
For Option 1:
vote_check = driver.find_element_by_xpath("//label[#for='96247410_725897453']")
For Option 2:
vote_check = driver.find_element_by_xpath("//label[#for='96247410_725897454']")
For Done:
vote_check = driver.find_element_by_xpath("//button[contains(text(), ' Done')]")
Try at your end and let me know.