I'm trying to use an extension that needs a config, so I thought to configure it and put the user-data
I'm using python 3.7 on Windows 10
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_argument("--user-data-dir=User/")
browser = webdriver.Chrome("chromedriver.exe", options = options)
I expect to open chrome with extensions, but when I run it, the folder user/default/extensions is empty (where they were the extensions)
Related
I'm trying to change my code to use an IE headless browser. The automation I'm doing is in a website that only works in internet explorer
My code was working great until I tried to use a headless browser
When I run this code, absolutely nothing happens, no error is thrown
# selenium 4
from selenium import webdriver
from selenium.webdriver.ie.service import Service
from webdriver_manager.microsoft import IEDriverManager
from selenium.webdriver.ie.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import StaleElementReferenceException
from dotenv import load_dotenv
# Inicialização do Selenium
ie_options = Options()
ie_options.ignore_zoom_level = True
## WORKS!
# driver = webdriver.Ie(service=Service(IEDriverManager().install()), options=ie_options)
## NOT WORKING
service = Service(executable_path=constantes.PATH_HEADLESS)
driver = webdriver.Ie(service=service, options=ie_options)
# Acessa a página
driver.get(constantes.URL)
I believe the reason why it seems nothing is happening is because you have no output (not printing anything). I'm not familiar with your process, but I tried it out with mine also using chrome and it worked fine. Context:
chrome_options = Options()
chrome_options.add_argument("--headless")
driver=webdriver.Chrome(service=Service('*executable
path'),options=chrome_options)
driver.get('https://stackoverflow.com/')
print(driver.title)
First off - no experience with Python, Sublime Text or Selenium - please be kind..
I am having an issue building a scraper in Python - using Sublime text, Selenium and Chrome. I have updated to the latest Python, Pip and downloaded the correct Chrome Driver. The webpage pops up fine, but get errors.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
#from selenium.webdriver.common.ui import WebDriverWait - commented out due to error
#from selenium.webdriver.common import expected_conditions as EC - commented out due to error
import time
driver = webdriver.Chrome("C:\Program Files (x86)\chromedriver.exe")
driver.get ("https://www.royalcaribbean.com/account/cruise-planner/category/pt_beverage/product/3222?bookingId=1429192&shipCode=NV&sailDate=20220907")
print(driver.find_element(by=By.CLASS_NAME, value='ng-tns-c210-4 text-promo-1').text)***
wait = WebDriverWait(driver, 20)
driver.get("https://www.royalcaribbean.com/account/cruise-planner/category/pt_beverage/product/3222?bookingId=1429192&shipCode=NV&sailDate=20220907")
elem=wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.ng-tns-c210-4.text-promo-1')))
print(elem.text)
Your class name is actually multiple class names so using css selector.
Outputs:
$80.99
Imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
The problem is that as the browser window open the Facebook page I expect it to click on the Create New Account .
The XPATH for Create New Account that I used is
//a[text()='Create New Account']
but it open's facebook.com then suddenly closes although I have other scripts working properly.
The complete Code :
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://facebook.com")
link_locator = '//a[text()="Create New Account"]'
create_account = Wait(driver, 5).until(EC.presence_of_element_located((By.XPATH, link_locator))).click()
Browser has been closed immediately, coz there was just command click, driver made it and due to nothing next, closed the driver.
Try to add time.sleep(10) at the end, and you will see that signup pop appeared:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait as Wait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://facebook.com")
link_locator = '//a[text()="Create New Account"]'
create_account = Wait(driver, 5).until(EC.presence_of_element_located((By.XPATH, link_locator))).click()
time.sleep(10)
driver.quit()
Every time chrome opens it's not on my profile, so I don't have all of my saved passwords an extensions.
I searched for a while and this is what came out.
Chrome still opens but it's not on my profile.
Can anyone tell me what I've done wrong?
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\Users\Utente\AppData\Local\Google\Chrome\User Data\Profile 1")
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.nike.com/it/launch?s=upcoming")
I think you need a comma after path and then define chrome_options like this:
driver = webdriver.Chrome(executable_path='C:\\path\\to\\chromedriver', chrome_options=options)
I am using the following code.
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#login
driver = webdriver.Chrome()
driver.get("url")
#time.sleep(10)
driver.set_window_size(920, 680)
driver.find_element(By.ID, "loginUserName").send_keys("xx")
driver.find_element(By.ID, "loginPassword").send_keys("yy")
driver.find_element(By.ID, "loginButton").click()
It is working fine for me and i'm not included any path and set property for chrome-extension. If i share this program,the opposite person is getting the following error and they have chromedriver.exe in python folder and in that same folder they created this python file
Traceback (most recent call last): File
"C:\Users\1025043\AppData\Local\Programs\Python\Python37-32\anu\1.py",
line 8, in
driver = webdriver.Chrome(chrome_driver_path) NameError: name 'chrome_driver_path' is not defined
In my path i am having,
['',
'C:\Users\1024983\AppData\Local\Programs\Python\Python37\python37.zip',
'C:\Users\1024983\AppData\Local\Programs\Python\Python37\DLLs',
'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib',
'C:\Users\1024983\AppData\Local\Programs\Python\Python37',
'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages',
'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages\win32',
'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages\win32\lib',
'C:\Users\1024983\AppData\Local\Programs\Python\Python37\lib\site-packages\Pythonwin']
What is the reason for this.?
Note: I am using Windows 10, Python 3.7.4 ,selenium 3.141.0 ,Chrome Version 78.0.3904.108(opposite person also using this version only)
The chromedriver.exe should be included in the executable PATH.
Download the chromedriver.exe and add this to the code as below. (add chrome driver path as it's located in your machine) or you can include in to the PATH variable in environment variables in windows 10.
E.g.
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#login
driver = webdriver.Chrome(executable_path=r'C:\chromedriver.exe')
driver.get("url")
#time.sleep(10)
driver.set_window_size(920, 680)
driver.find_element(By.ID, "loginUserName").send_keys("xx")
driver.find_element(By.ID, "loginPassword").send_keys("yy")
driver.find_element(By.ID, "loginButton").click()