file and then click the submit button
for some reason after i run the python script .It justs opens the upload window
and sits there
here is my code .I am using python on windows 10
from selenium import webdriver
driver =
webdriver.Chrome(executable_path='C:\chromedriver\chromedriver.exe')
driver.get('http://localhost:5000/upload')
element =
driver.find_element_by_id("uploadfile").send_keys("c:\\projects\\input.xml")
modified code --working
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = "/usr/bin/chromium"
driver =
webdriver.Chrome(executable_path='C:\chromedriver\chromedriver.exe')
driver.get('http://localhost:5000/uploadxml')
element =
driver.find_element_by_id("uploadfile")
.send_keys("c:\\projects\\inout.xml")
click = driver.find_element_by_id("submitfile")
click.click()
You only select the element. But you don't klick the submit.
Take this code snippet after your select.
click = driver.find_element_by_id("**id**")
click.click()
Related
I'd like to open a chrome window with my default profile using selenium. I'm using a mac.
This is the code I have so far.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
import time
options = Options()
options.add_argument('user-data-dir=/Users/USERNAME/Library/Application Support/Google/Chrome')
options.add_argument('profile-directory=Default')
##options.add_argument("user-data-dir=/Users/USERNAME/Library/Application Support/Google/Chrome/Default")
driver = webdriver.Chrome(chrome_options=options)
driver.get('https://www.selenium.dev/')
## find element using xpath
l = driver.find_element('xpath', '//a[#href="/documentation/webdriver/"]')
## click button
driver.execute_script("arguments[0].click();", l);
## print resultant page title
print("Page title is: ")
print(driver.title)
When I remove line 8, which is
options.add_argument('user-data-dir=/Users/USERNAME/Library/Application Support/Google/Chrome')
the code works just fine, but the chrome window isn't signed in. When I add that line, the chrome window opens logged in, but doesn't go to any website.
Any help would be appreciated!
I want to open profile in selenium (for login in whatsapp for once) like the below code but when run my code chrome open a second tab with this url:http://%3D%20c/Users/Ali/AppData/Local/Google/Chrome/User%20Data/Default
from selenium import webdriver
from selenium.webdriver import ChromeOptions
PATH = "chromedriver.exe"
url = "https://web.whatsapp.com/"
CH_Option = ChromeOptions()
CH_Option.add_argument("user-data-dir = C:/Users/Ali/AppData/Local/Google/Chrome/User Data/Default")
Driver = webdriver.Chrome(PATH,options=CH_Option)
Driver.get(url)
......ScreenShot.....
To fix this, change the add_argument line to (removing the spaces in the string):
CH_Option.add_argument("user-data-dir=C:/Users/Ali/AppData/Local/Google/Chrome/User Data/Default")
Try to change / in your path to \\
CH_Option.add_argument("user-data-dir=C:\\Users\\Ali\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
Try to create a Guest user profile in your chrome driver and change the path to
CH_Option.add_argument("user-data-dir=C:\\Users\\Ali\\AppData\\Local\\Google\\Chrome\\User Data\\Guest Profile")
Could you please help me automate clicking a webpage button using Python and Selenium?
Here's an example of a Python code that I have so far, which opens the browser using my profile, goes to the webpage.
However, it never interacts with the page:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:/Users/mohamed.a.eshra/AppData/Local/Google/Chrome/User Data") #Path to your chrome profile
url = 'https://google.com/'
driver = webdriver.Chrome(executable_path="C:/tools/selenium/chromedriver.exe", chrome_options=options)
driver.get(url)
inputtext = driver.find_element_by_name("Search").sendkeys("This is a test")
search = driver.find_element_by_name("btnk").click()
Could you please help me improve it to be able to click on a webpage button?
Thank you!
You can try following code:
url = 'https://google.com/'
driver = webdriver.Chrome(executable_path="C:/tools/selenium/chromedriver.exe", chrome_options=options)
driver.get(url)
inputtext = driver.find_element_by_name('q')
inputtext.send_keys('This is a test')
inputtext.submit()
As a test, I am trying to create a script that goes to my website and clicks on the learn more button, but am having trouble actually automatically clicking the button.
I've tried everything that I've found on stack overflow but nothing has worked.
from selenium import webdriver
import webbrowser
import time
url = 'https://www.mwstan.com'
driver = webbrowser.open_new_tab(url)
element = driver.find_element_by_id('learnmore')
element.click()
You are going to need to install a binary for whatever driver you are going to use
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=1920x1080")
chrome_driver = os.getcwd() + "/chromedriver"
def get_url_example(url):
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=chrome_driver)
driver.get(url)
button = driver.find_element_by_id("learnmore")
button.click()
# you can access the page source here using driver.page_source
if __name__ == '__main__':
get_url_page_source("https://www.mwstan.com")
This code works for me and hits your button.
This is using chrome webdriver but you can use another webdriver. JUst makesure you move the driver and access the path correctly like in line
chrome_driver = os.getcwd() + "/chromedriver"
When I'm trying to open a web page, its opening in a new chrome window stripped of all the extensions and modules. I'm not able to emulate the certain behavior of the website using selenium chrome browser window but I'm able to do the same thing in a normal chrome window without any issues.
from selenium import webdriver
driver = webdriver.Chrome(r'C:\chromedriver.exe')
driver.get("remote_worksplace_link")
id_box = driver.find_element_by_id('Enter user name')
id_box.send_keys('123456')
pass_box = driver.find_element_by_id('passwd')
pass_box.send_keys('123abc')
login_button = driver.find_element_by_id('Log_On')
login_button.click()
driver.implicitly_wait(2)
launch_button = driver.find_element_by_class_name('storeapp-icon ui-sortable-handle')
launch_button.click()
driver.implicitly_wait(5)
driver.close()
all extentions has its .crx file just you need to add those path
chrome_options = Options()
chrome_options.add_extension('path_to_extension')
driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
driver.get("url")
driver.quit()