Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Webdriver-Python-Leboncin(分类)-pb选择下拉列表&;箱_Python_Selenium_Selenium Webdriver_Dropdownbox - Fatal编程技术网

Selenium Webdriver-Python-Leboncin(分类)-pb选择下拉列表&;箱

Selenium Webdriver-Python-Leboncin(分类)-pb选择下拉列表&;箱,python,selenium,selenium-webdriver,dropdownbox,Python,Selenium,Selenium Webdriver,Dropdownbox,我继续学习Python/Selenium 成功连接到站点并选择按钮后,我想填充字段以提交分类广告 在这个阶段,我尝试选择两个字段,一个下拉列表和一个框。 Html如下所示 下拉列表 <div class="selectWrapper single"> <select id="category" class="select" name="category"> <option value="0">«Choisissez une catégorie»</op

我继续学习Python/Selenium

成功连接到站点并选择按钮后,我想填充字段以提交分类广告

在这个阶段,我尝试选择两个字段,一个下拉列表和一个框。 Html如下所示

下拉列表

<div class="selectWrapper single">
<select id="category" class="select" name="category">
<option value="0">«Choisissez une catégorie»</option>
<option id="cat71" value="71" style="background-color:#E6E6E6" disabled="">-- EMPLOI --</option>
<option id="cat33" value="33">Offres d'emploi</option>
<option id="cat1" value="1" style="background-color:#E6E6E6" disabled="">-- VEHICULES --</option>
<option id="cat2" value="2">Voitures</option>
<option id="cat3" value="3">Motos</option>
<option id="cat4" value="4">Caravaning</option>
<option id="cat5" value="5">Utilitaires</option>
<option id="cat6" value="6">Equipement Auto</option>
<option id="cat44" value="44">Equipement Moto</option>
<option id="cat50" value="50">Equipement Caravaning</option>
<option id="cat7" value="7">Nautisme</option>
<option id="cat51" value="51">Equipement Nautisme</option>
<option id="cat8" value="8" style="background-color:#E6E6E6" disabled="">-- IMMOBILIER --</option>
<option id="cat9" value="9">Ventes immobilières</option>
<option id="cat10" value="10">Locations</option>
<option id="cat11" value="11">Colocations</option>
<option id="cat13" value="13">Bureaux & Commerces</option>
<option id="cat66" value="66" style="background-color:#E6E6E6" disabled="">-- VACANCES --</option>
<option id="cat12" value="12">Locations & Gîtes</option>
<option id="cat67" value="67">Chambres d'hôtes</option>
<option id="cat68" value="68">Campings</option>
<option id="cat69" value="69">Hôtels</option>
<option id="cat70" value="70">Hébergements insolites</option>
<option id="cat14" value="14" style="background-color:#E6E6E6" disabled="">-- MULTIMEDIA --</option>
<option id="cat15" value="15">Informatique</option>
<option id="cat43" value="43">Consoles & Jeux vidéo</option>
<option id="cat16" value="16">Image & Son</option>
<option id="cat17" value="17">Téléphonie</option>
<option id="cat18" value="18" style="background-color:#E6E6E6" disabled="">-- MAISON --</option>
<option id="cat19" value="19">Ameublement</option>
<option id="cat20" value="20">Electroménager</option>
<option id="cat45" value="45">Arts de la table</option>
<option id="cat39" value="39">Décoration</option>
<option id="cat46" value="46">Linge de maison</option>
<option id="cat21" value="21">Bricolage</option>
<option id="cat52" value="52">Jardinage</option>
<option id="cat22" value="22">Vêtements</option>
<option id="cat53" value="53">Chaussures</option>
<option id="cat47" value="47">Accessoires & Bagagerie</option>
<option id="cat42" value="42">Montres & Bijoux</option>
<option id="cat23" value="23">Equipement bébé</option>
<option id="cat54" value="54">Vêtements bébé</option>
<option id="cat24" value="24" style="background-color:#E6E6E6" disabled="">-- LOISIRS --</option>
<option id="cat25" value="25">DVD / Films</option>
<option id="cat26" value="26">CD / Musique</option>
<option id="cat27" value="27">Livres</option>
<option id="cat28" value="28">Animaux</option>
<option id="cat55" value="55">Vélos</option>
<option id="cat29" value="29">Sports & Hobbies</option>
<option id="cat30" value="30">Instruments de musique</option>
<option id="cat40" value="40">Collection</option>
<option id="cat41" value="41">Jeux & Jouets</option>
<option id="cat48" value="48">Vins & Gastronomie</option>
<option id="cat56" value="56" style="background-color:#E6E6E6" disabled="">-- MATERIEL PROFESSIONNEL --</option>
<option id="cat57" value="57">Matériel Agricole</option>
<option id="cat58" value="58">Transport - Manutention</option>
<option id="cat59" value="59">BTP - Chantier Gros-oeuvre</option>
<option id="cat60" value="60">Outillage - Matériaux 2nd-oeuvre</option>
<option id="cat32" value="32">Équipements Industriels</option>
<option id="cat61" value="61">Restauration - Hôtellerie</option>
<option id="cat62" value="62">Fournitures de Bureau</option>
<option id="cat63" value="63">Commerces & Marchés</option>
<option id="cat64" value="64">Matériel Médical</option>
<option id="cat31" value="31" style="background-color:#E6E6E6" disabled="">-- SERVICES --</option>
<option id="cat34" value="34">Prestations de services</option>
<option id="cat35" value="35">Billetterie</option>
<option id="cat49" value="49">Evénements</option>
<option id="cat36" value="36">Cours particuliers</option>
<option id="cat65" value="65">Covoiturage</option>
<option id="cat37" value="37" style="background-color:#E6E6E6" disabled="">-- -- --</option>
<option id="cat38" value="38">Autres</option>
</select>
</div>
<span class="label-error full " data-for="category"></span>
</div>
对于两者,我都有一个错误

错误消息

Traceback (most recent call last):
  File "connectionwebdriver2", line 31, in test_connectionwebdriver2
    driver.find_element_by_xpath("//*[@id='cat10']").click()
  File "/Users/olivierhoen/scrap/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 385, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/Users/olivierhoen/scrap/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 955, in find_element
    'value': value})['value']
  File "/Users/olivierhoen/scrap/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "/Users/olivierhoen/scrap/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
虽然我读过不同的帖子和selenium文档,但我还是有点被卡住了

提前感谢您的支持

最好的

完整的Python代码(我已设置了特定的凭据)

这应该适合您:)

要查找元素的xpath,请执行以下操作:

编辑: 只是对代码做了一些修改来测试它,它在firefox中工作得非常好

driver = webdriver.Firefox()
driver.maximize_window()
base_urldr = "https://compteperso.leboncoin.fr/account/index.html"
verificationErrors = []
accept_next_alert = True
driver.implicitly_wait(10)

wait = WebDriverWait(driver,10)
driver.get(base_urldr)
driver.find_element_by_name("st_username").clear()
driver.find_element_by_name("st_username").send_keys("thecoingood@gmail.com")
driver.find_element_by_name("st_passwd").clear()
driver.find_element_by_name("st_passwd").send_keys("thecoingood1")
driver.find_element_by_id("connect_button").click()
#driver.get("https://www2.leboncoin.fr/ai?ca=15_s")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='deposer']"))).click()
driver.find_element_by_xpath("//*[@id='cat10']").click()
driver.find_element_by_xpath("//*[@id='subject']").send_keys("test")
time.sleep(10)

发布您的错误消息。感谢您的回复。我有相同的pb selenium.common.exceptions.WebDriverException:消息:处理命令时发生未知的服务器端错误。能否复制所有代码并将其粘贴到回复中?另外,试着运行我为你编写的代码,看看它是否有效。我已经用完整的代码编辑了这个问题,包括你的代码。请注意,我使用的是Safari web驱动程序(不确定是否有区别)。哦,我知道问题出在哪里了,您不能使用Safari,您需要使用Firefox或Chrome.:)谢谢,塞布。我使用的是MacOs中包含的嵌入式驱动程序。我目前正在审查如何安装gecko驱动程序。一旦完成并成功,我将结束主题。
Traceback (most recent call last):
  File "connectionwebdriver2", line 31, in test_connectionwebdriver2
    driver.find_element_by_xpath("//*[@id='cat10']").click()
  File "/Users/olivierhoen/scrap/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 385, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "/Users/olivierhoen/scrap/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 955, in find_element
    'value': value})['value']
  File "/Users/olivierhoen/scrap/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "/Users/olivierhoen/scrap/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class Connectionwebdriver2(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Safari()
        self.driver.maximize_window()
        self.base_urldr = "https://compteperso.leboncoin.fr/account/index.html"
        self.verificationErrors = []
        self.accept_next_alert = True
        self.driver.implicitly_wait(10)

    def test_connectionwebdriver2(self):
        driver = self.driver
        wait = WebDriverWait(driver,10)
        driver.get(self.base_urldr)
        driver.find_element_by_name("st_username").clear()
        driver.find_element_by_name("st_username").send_keys("thecoingood@gmail.com")
        driver.find_element_by_name("st_passwd").clear()
        driver.find_element_by_name("st_passwd").send_keys("thecoingood1")
        driver.find_element_by_id("connect_button").click()
        #driver.get("https://www2.leboncoin.fr/ai?ca=15_s")
        WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='deposer']"))).click()
        driver.find_element_by_xpath("//*[@id='cat10']").click()
        driver.find_element_by_xpath("//*[@id='subject']").send_keys("test")
        time.sleep(10)
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.leboncoin.fr/ai/form/0")
driver.find_element_by_xpath("//*[@id='cat10']").click()
driver.find_element_by_xpath("//*[@id='subject']").send_keys("test")
driver = webdriver.Firefox()
driver.maximize_window()
base_urldr = "https://compteperso.leboncoin.fr/account/index.html"
verificationErrors = []
accept_next_alert = True
driver.implicitly_wait(10)

wait = WebDriverWait(driver,10)
driver.get(base_urldr)
driver.find_element_by_name("st_username").clear()
driver.find_element_by_name("st_username").send_keys("thecoingood@gmail.com")
driver.find_element_by_name("st_passwd").clear()
driver.find_element_by_name("st_passwd").send_keys("thecoingood1")
driver.find_element_by_id("connect_button").click()
#driver.get("https://www2.leboncoin.fr/ai?ca=15_s")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='deposer']"))).click()
driver.find_element_by_xpath("//*[@id='cat10']").click()
driver.find_element_by_xpath("//*[@id='subject']").send_keys("test")
time.sleep(10)