I was trying to run this script to automate and click on the product list in the webpage using selenium. But this "raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: error" is occurring every time. What is wrong I'm doing here? Expecting your guidance.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from shutil import which
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
chrome_options = Options()
chrome_options.add_argument('__headless')
chrome_path = which('chromedriver')
driver = webdriver.Chrome(executable_path=chrome_path, options=chrome_options)
driver.set_window_size(1920, 1080)
driver.get('https://www.galaxus.ch/search?q=5010533606001')
product_tab = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//article[#class='panelProduct panelLayout_panelLayout__BDQ6_ view_product__3AOqY']/a"))).click()
time.sleep(10)
driver.close()
output
PS G:\Python_Practice\scrapy_practice\test> [21628:13792:0911/125833.339:ERROR:gpu_init.cc(441)] Passthrough is not supported, GL is disabled
> & C:/Users/raisu/anaconda3/envs/Scrapy_Workspace2/python.exe g:/Python_Practice/scrapy_practice/test/test.py
DevTools listening on ws://127.0.0.1:56456/devtools/browser/1d6d20ce-ecb9-44f7-be6e-1dbe1373526a
Traceback (most recent call last):
File "g:/Python_Practice/scrapy_practice/test/test.py", line 18, in <module>
product_tab = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//article[#class='panelProduct panelLayout_panelLayout__BDQ6_ view_product__3AOqY']/a"))).click()
File "C:\Users\raisu\anaconda3\envs\Scrapy_Workspace2\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Instead of using the xpath, I've used a CSS_SELECTOR and also I changed the wait condition for element to be visible
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from shutil import which
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
chrome_options = Options()
chrome_options.add_argument('__headless')
chrome_path = which('chromedriver')
driver = webdriver.Chrome(executable_path=chrome_path, options=chrome_options)
driver.set_window_size(1920, 1080)
driver.get('https://www.galaxus.ch/search?q=5010533606001')
#time.sleep(5) use this only if the wait is not working
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'article > a')))
driver.find_element(By.CSS_SELECTOR,'article > a').click()
driver.close()
Related
My problem is that I want to execute the whole code, but it just opens Chrome and stops the program. What could be the reason for this? I installed every package needed such as the chromedriver into the same directory as the scriptfile.[![enter image description here][1]][1]
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
time.sleep(5)
# Öffne die angegebene URL
driver.get("https://www.nike.com/de/launch/t/air-force-1-07-fresh")
# Warte bis die Seite geladen ist
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.CLASS_NAME, "size-grid-button")))
# Scrolle nach unten
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Warte 3 Sekunden
import time
time.sleep(3)
# Wähle Größe 9 aus
size_button = driver.find_element_by_xpath('//*\[#class="size-grid-button" and contains(text(),"9")\]')
size_button.click()
# Drücke den Kauf-Knopf
buy_button = driver.find_element_by_class_name("buying-tools-cta-button")
buy_button.click()
# Gib die Nachricht "Zugriff erfolgt" zurück
print("Zugriff erfolgt")]
Snapshot:
Incase you are using selenium4 you need to pass the argument:
ChromeDriverManager().install()
along with the service keyword as follows:
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://www.nike.com/de/launch/t/air-force-1-07-fresh")
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.common.exceptions import NoSuchElementException,TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support import expected_conditions
driver = webdriver.Chrome(executable_path = r"C:\Users\mvintee\project_for_selenium\chromedriver_win32\chromedriver.exe")
actions = ActionChains(driver)
driver.get("http://pis033/NorthStarWMS/User/PurchaseOrders.aspx?t=1&PO=1")
driver.maximize_window()
#driver.implicitly_wait(100)
print(driver.title)
driver.find_element("id","Login1_UserName").send_keys("wms")
driver.find_element("id","Login1_Password").send_keys("1")
driver.find_element("class name","rbText").click()
element_to_hover_over=driver.find_element("xpath",'//*[#id="ctl00_MenuTabNew"]/ul/li[4]/span/span')
time.sleep(5)
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()
time.sleep(5)
driver.find_element("xpath", '//*[#id="ctl00_MenuTabNew"]/ul/li[4]/div/ul/li[1]/a/span').click()
time.sleep(5)
driver.find_element("id","ctl00_ContentPlaceHolder1_ShipOrderGrid_ctl00_ctl02_ctl00_btnAdd").click()
element=driver.find_element("id",'btnSave')
time.sleep(5)
element.click()
driver.quit()
Nothing happen when i locate element of save button. Rest of the code is working correct. I have tried all most everything but still locators not working.
This is my code where all things are alright but at last when i click on save button its not working. I have tried accessing element by id, name, xpath and class name of the save button but click for save not working. When that part need to executed nothing happen.Rest of the program executing properly.Plz suggest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
driver = webdriver.Chrome(executable_path = r"C:\Users\mvintee\project_for_selenium\chromedriver_win32\chromedriver.exe")
actions = ActionChains(driver)
driver.get("http://pis033/NorthStarWMS/User/PurchaseOrders.aspx?t=1&PO=1")
print(driver.title)
driver.find_element("id","Login1_UserName").send_keys("wms")
driver.find_element("id","Login1_Password").send_keys("1")
driver.find_element("class name","rbText").click()
time.sleep(5)
element_to_hover_over=driver.find_element("xpath",'//*[#id="ctl00_MenuTabNew"]/ul/li[4]/span/span')
time.sleep(5)
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()
time.sleep(5)
driver.find_element("xpath", '//*[#id="ctl00_MenuTabNew"]/ul/li[4]/div/ul/li[1]/a/span').click()
#time.sleep(5)
driver.find_element("id","ctl00_ContentPlaceHolder1_ShipOrderGrid_ctl00_ctl02_ctl00_btnAdd").click()
#time.sleep(5)
driver.find_element("class name",'RadButton RadButton_Hay rbLinkButton btn_new_bg_popUpnew').click()
#time.sleep(5)
element=driver.find_element("xpath",'//*[#id="btnSave"]').click()
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
driver = webdriver.Chrome(executable_path = r"C:\Users\mvintee\project_for_selenium\chromedriver_win32\chromedriver.exe")
actions = ActionChains(driver)
driver.get("http://pis033/NorthStarWMS/User/PurchaseOrders.aspx?t=1&PO=1")
print(driver.title)
driver.find_element("id","Login1_UserName").send_keys("wms")
driver.find_element("id","Login1_Password").send_keys("1")
driver.find_element("class name","rbText").click()
time.sleep(5)
element_to_hover_over=driver.find_element("xpath",'//*[#id="ctl00_MenuTabNew"]/ul/li[4]/span/span')
time.sleep(5)
hover = ActionChains(driver).move_to_element(element_to_hover_over)
hover.perform()
time.sleep(5)
driver.find_element("xpath", '//*[#id="ctl00_MenuTabNew"]/ul/li[4]/div/ul/li[1]/a/span').click()
#time.sleep(5)
driver.find_element("id","ctl00_ContentPlaceHolder1_ShipOrderGrid_ctl00_ctl02_ctl00_btnAdd").click()
#time.sleep(5)
driver.find_element("class name",'RadButton RadButton_Hay rbLinkButton btn_new_bg_popUpnew').click()
#time.sleep(5)
element=driver.find_element("xpath",'//*[#id="btnSave"]').click()
I'm trying to grab the price from this page: https://www.eq3.com/ca/en/product/cjv8cke45026q01786nahx8uf/lighting/lighting/pendant-lamps/nelson-bell-bubble-pendant-lamp?cjv49km02036401865sece5be=cjv49km0503650186hc90zvnq
It should be getting $1,376.15 CAD however I'm getting some other text from the page and sometimes it doesn't work at all and gives me:
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Here's my code:
DRIVER_PATH = '/usr/bin/chromedriver'
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(executable_path=DRIVER_PATH, options=options)
XPATH = '//*[#id="app"]/main/div/div/section[1]/div/div[3]/div/span[1]'
url = 'https://www.eq3.com/ca/en/product/cjv8cke45026q01786nahx8uf/lighting/lighting/pendant-lamps/nelson-bell-bubble-pendant-lamp?cjv49km02036401865sece5be=cjv49km0503650186hc90zvnq'
driver.get(url)
price = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, XPATH)))
print(price)
driver.quit()
Try that out:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support import expected_conditions as EC
DRIVER_PATH = '/usr/bin/chromedriver'
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(executable_path=DRIVER_PATH, options=options)
url = "https://www.eq3.com/ca/en/product/cjv8cke45026q01786nahx8uf/lighting/lighting/pendant-lamps/nelson-bell-bubble-pendant-lamp?cjv49km02036401865sece5be=cjv49km0503650186hc90zvnq"
driver.get(url)
el = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[contains(#class,'MuiTypography-root') and contains(#class,'MuiTypography-h3')][1]")))
text = el.text
print(text)
driver.quit()
I have it as wait until clickable so I can keep reloading on my own but i want it to just do it on it's own because constantly reloading isn't fun and is a waste of time
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
driver = webdriver.Chrome()
driver.get('link.com')
wait = WebDriverWait(driver, 1000)
AddToKart = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[#id="content"]/div/div/div[1]/div[3]/div[1]/section[2]/section/div[15]/div/div[2]/button'))).click()```
wait = WebDriverWait(driver, 5)
count = 1
while(count==1):
count=0
try:
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[#id="content"]/div/div/div[1]/div[3]/div[1]/section[2]/section/div[15]/div/div[2]/button'))).click()
except Exception as e:
print(e)
count=1
try:
driver.refresh()
except Exception as e:
print(e)
Just wrapp it with while and try/except