Je rencontre un problème pour sélectionner une option dans le menu déroulant. Le site est https://uk.farnell.com . Il y a une liste déroulante Tout juste avant la zone de texte Rechercher. Je veux sélectionner "Condensateurs céramiques" dans le menu déroulant. J'ai essayé de différentes manières comme utiliser
5 Réponses :
xpath for All - .//div[@id='catContainer']
xpath pour les condensateurs céramiques - .//option[text()='Ceramic Capacitors']
Sélectionnez par 3ème index ou par texte visible.
from selenium.webdriver.support.select import Select
Importer
driver.get('https://uk.farnell.com/') Select(driver.find_element_by_id('categoryIdBox')).select_by_index(3) Select(driver.find_element_by_id('categoryIdBox')).select_by_visible_text("Ceramic Capacitors")
Veuillez essayer avec le code ci-dessous:
WebElement dropdownlist=Driver.findElement(By.id("categoryIdBox")); Select listbox = new Select(dropdownlist); listbox.selectByVisibleText("Ceramic Capacitors");
Pouvez-vous essayer le code ci-dessous, il pourrait aider à résoudre votre problème
WebElement element = driver.findElement(By.xpath("((//div[@id='catContainer']//following-sibling::select))")); Select selectOption = new Select(element); selectOption.selectByIndex(3); WebElement option = selectOption.getFirstSelectedOption(); * This is used just to verify the selected option System.out.println(option.getText());
Veuillez utiliser le code ci-dessous:
Select options = new Select(driver.findElement(By.xpath("//select[@id='categoryIdBox']"))); options.selectByVisibleText("Ceramic Capacitors");