[英]Selenium Webdriver - Python - leboncoin (classified) - pb to select a dropdown list & box
[英]Selenium Webdriver - Python - leboncoin - pb to select a button with an accent
我正在尝试在以下网站上自动填写表格:' https://www.leboncoin.fr/ '
我用 Selenium IDE 录制了一个脚本。
我有一个功能,可以通过单击“Se 连接器”按钮并填写我的密码和用户名来自动连接。 它工作正常
我已经为这个主题设置了特定的凭证电子邮件:thecoingood@gmail.com pwd:thecoingood1
代码是
# -*- 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.implicitly_wait(30)
self.driver.maximize_window()
self.base_urldr = "https://compteperso.leboncoin.fr/account/index.html"
self.verificationErrors = []
self.accept_next_alert = True
def test_connectionwebdriver2(self):
driver = self.driver
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")
my_annonce = WebDriverWait(self.driver, 10)\
.until(EC.element_to_be_clickable((By.LINK_TEXT, "Supprimer")))
my_annonce.click()
#time.sleep(10)
#driver.find_element_by_link_text("Supprimer").click()
#WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@href='//https://compteperso.leboncoin.fr/account/index.html?ca=12_s' and contains(.,'posez une annonce')]"))).click()
#Select(driver.find_element_by_id("category")).select_by_visible_text('Locations')
#Select(driver.find_element_by_id('cat10')).select()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main(verbosity=2)
连接后,我被重定向到https://compteperso.leboncoin.fr/account/index.html?ca=12_s (问题:selenium 中使用的对象是用这个新地址更新的还是仍然坚持可能创建的初始地址问题)
当我尝试点击
<a href="//www2.leboncoin.fr/ai?ca=15_s">Déposez une annonce</a>
使用此代码
driver.find_element_by_link_text(u"Déposez une annonce").click()
没有任何反应(没有错误)。
我认为这与链接尚不可见有关。 我试图添加 time.sleep() 并且还阅读了
如何让 Selenium Web Driver 等待元素可访问,而不仅仅是存在?
但无法解决这个问题。 我可以添加到该页面的直接链接,但我想了解一下。
提前致谢
根据您的问题,单击选项卡/文本链接作为Déposez une annonce ,您可以使用以下代码行:
要单击带有Déposez une annonce文本的TAB
,请使用:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[@class='deposer']/a[contains(@href,'//www2.leboncoin.fr/ai?ca=') and contains(.,'une annonce')]"))).click()
要单击带有Déposez une annonce文本的BUTTON
,请使用:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='create']/a[contains(@href,'//www2.leboncoin.fr/ai?ca=') and contains(.,'une annonce')]"))).click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.