lundi 27 septembre 2021

( Beginner ) If variable selenium on python

I'm new to coding and I'm trying to learn webpage automation with Selenium.

So far I have managed to open a webpage, make it click where I want it to click and input any words I want. However, I'm struggling with the if variable.

Basically I want to tell Selenium to click a button that I located by xpath. In turn this button should display a new element on the screen that I can also locate by xpath. However, sometimes when I click this button the new element doesn't display. So how can I tell Selenium that if the element doesn't display it should refresh the page and click until the new element is displayed and only then it can click on the new element?

Code:

from selenium import webdriver

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.common.keys import Keys

from selenium.common.exceptions import NoSuchElementException


driver = webdriver.Firefox()

url = "https://www.compumsa.eu/item/GV-R55XTOC-4GD-Gigabyte-Radeon-RX-5500-XT-4GB-OC-PCIE-9320"

driver.get(url)

driver.maximize_window()

click = driver.find_element_by_xpath('//*[@id="ContentPlaceHolderMain_LBAddItem"]')

click.click()

itempanier = driver.find_element_by_xpath('//*[@id="SpanCaddy"]')


if (itempanier.is_displayed()

Aucun commentaire:

Enregistrer un commentaire