Selenium Webdriver - Python - leboncoin - pb 选择带重音的按钮

2024-05-09

我正在尝试在以下网站上自动填写表格:'https://www.leboncoin.fr/ https://www.leboncoin.fr/'

我用 Selenium IDE 录制了一个脚本。

我有一个通过单击“Se 连接器”按钮并填写我的密码和用户名来自动连接的功能。效果很好

我已经为此主题设置了特定凭证 电子邮件:[电子邮件受保护] /cdn-cgi/l/email-protection密码: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("[email protected] /cdn-cgi/l/email-protection ")
        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 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 驱动程序等待元素可访问,而不仅仅是存在? https://stackoverflow.com/questions/9161773/how-can-i-get-selenium-web-driver-to-wait-for-an-element-to-be-accessible-not-j

但无法解决这个问题。我可以添加到该页面的直接链接,但我想了解一下。

提前致谢


根据您的问题点击tab / link文本为下令宣布您可以使用以下代码行:

  • 要单击TAB文本为下令宣布 use :

    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()
    
  • 要单击BUTTON文本为下令宣布 use :

    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()
    
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Selenium Webdriver - Python - leboncoin - pb 选择带重音的按钮 的相关文章

  • Windows 中的 Python 多处理池奇怪行为

    Python 多处理池在 Linux 和 Windows 之间有不同的行为 当按工作人员数量运行方法映射时 在 Linux 中 它会在您作为参数提供的特定函数的范围内运行该进程 但在 Windows 中 每个工作进程都在父进程的范围内运行
  • 从 Python 中的 message_from_string() 获取发件人地址

    有人可以告诉我如何在Python中从email message from string 获取发件人地址吗 谢谢 我试过 message email message from string email text from message Fr
  • setColumnStretch 和 setRowStretch 如何工作

    我有一个使用构建的应用程序PySide2它使用setColumnStretch用于柱拉伸和setRowStretch用于行拉伸 它工作得很好 但我无法理解它是如何工作的 我参考了 qt 文档 但它对我没有帮助 我被困在括号内的两个值上 例如
  • 嵌套函数中的变量作用域

    有人可以解释为什么以下程序失败 def g f for in range 10 f def main x 10 def f print x x x 1 g f if name main main 带有消息 Traceback most re
  • 如何在Python中反转列表的列表? [复制]

    这个问题在这里已经有答案了 我想知道如何反转 python 中的列表列表 例如 原来的 list 1 2 3 4 5 6 7 8 9 输出 new list 7 8 9 4 5 6 1 2 3 现在 我正在尝试这样做 new list re
  • Python正则表达式替换引号中的文本(引号本身除外)

    例如 我有一个测试字符串 content I opened my mouth Good morning I said cheerfully 我想使用正则表达式删除双语音标记之间的文本 但不删除语音标记本身 所以它会返回 I opened m
  • Python:处理图像并保存到文件流

    我需要使用 python 处理图像 应用过滤器和其他转换 然后使用 HTTP 将其提供给用户 现在 我正在使用 BaseHTTPServer 和 PIL 问题是 PIL 无法直接写入文件流 因此我必须写入临时文件 然后读取该文件 以便将其发
  • python 硒 按名称查找元素

    查找电子邮件输入的正确代码是什么https accounts google com ServiceLogin html 是
  • python os.fork 使用相同的 python 解释器吗?

    据我所知 Python 中的线程使用相同的 Python 解释器实例 我的问题是与创建的流程相同os fork 或者每个进程创建的os fork有自己的翻译吗 每当你 fork 时 整个 Python 进程都会在内存中复制 包括Python
  • 在 Python 中引发异常的正确方法是什么? [复制]

    这个问题在这里已经有答案了 这是简单的代码 import sys class EmptyArgs StandardError pass if name main The first way to raise an exception if
  • 使用 Popen 打开进程并获取 PID

    我正在开发一个漂亮的小功能 def startProcess name path Starts a process in the background and writes a PID file returns integer pid Ch
  • 如何在使用 Flask for Python 3 的同时使用 Bootstrap 4?

    我检查过 发现默认安装时 Flask Bootstrap 原生使用 Bootstrap 3 3 7 但实际上我想通过使用 Flask Bootstrap 包在我的项目中使用 Bootstrap 4 任何有关如何更新它或类似内容的帮助将不胜感
  • 如何读取多个文件并将它们合并到一个 pandas 数据框中?

    我想读取位于同一目录中的多个文件 然后将它们合并到一个 pandas 数据框中 如果我这样做的话它会起作用 import pandas as pd df1 pd read csv data 12015 csv df2 pd read csv
  • 从 SUDS 中的 SOAP 响应中提取 Cookie

    我必须使用具有多种服务的 API 所有这些都需要来自下面的身份验证的 JSESSION cookie 然而 当我调用下一个服务时 它不会保留 cookie 因此会拒绝它们 from suds client import Client url
  • 从函数在 python 3 中创建全局变量

    我想知道为什么在函数结束后我无法访问变量 variable for raw data 代码是这样的 def htmlfrom Website URL import urllib request response urllib request
  • model.predict() 返回类而不是概率

    Hello 我是第一次使用 Keras 我训练并保存了一个模型 作为 json 文件及其权重 该模型旨在将图像分为 3 个类别 我的编译方法 model compile loss categorical crossentropy optim
  • 如何使用 Matplotlib 可视化标量二维数据?

    所以我有一个网格网格 矩阵 X 和 Y 以及标量数据 矩阵 Z 我需要将其可视化 最好是一些 2D 图像 在各点处带有颜色 显示 Z 值 我做了一些研究 但没有找到任何能完全满足我想要的效果的东西 pyplot imshow Z 看起来不错
  • 如何从 Anaconda 更新 Pandas 以及最后是否可以使用 eclipse

    我已经使用以下文档通过 Anaconda 安装了 Python http www kevinsheppard com images 0 09 Python introduction pdf http www kevinsheppard co
  • Docker Python 脚本找不到文件

    我已经成功构建了一个 Docker 容器 并将应用程序的文件复制到 Dockerfile 中的容器中 但是 我正在尝试执行引用输入文件 在 Docker 构建期间复制到容器中 的 Python 脚本 我似乎无法弄清楚为什么我的脚本告诉我它无
  • nltk 标记化和缩写

    我用 nltk 对文本进行标记 只是将句子输入到 wordpunct tokenizer 中 这会拆分缩写 例如 don t 到 don t 但我想将它们保留为一个单词 我正在改进我的方法 以实现更精确的文本标记化 因此我需要更深入地研究

随机推荐