【问题标题】:Python Selenium - how to get confirmation after submitPython Selenium - 提交后如何获得确认
【发布时间】:2021-09-17 22:23:26
【问题描述】:

我对此post 有一个后续问题,我想在点击提交按钮后获得任何确认文本。代码是否有效。

html - 无效示例

<div class="serialModalArea js-serial-modal">
        <div class="serialModal">
            <div class="serialModal__notes">
                <img class="iconGlobal" src="/img/nav/nav_exclamation.svg"> <span>Invalid entry.</span>
            </div>
            <p class="serialModal__message js-modal-message"></p>
            <button type="button" class="serialModal__btn js-modal-btn">Close</button>
        </div>
    </div>

html - 送礼示例

<div class="serialModalArea js-serial-modal success" style="display: block;">
        <div class="serialModal">
            <div class="serialModal__notes">
                <img class="iconGlobal" src="/img/nav/nav_exclamation.svg"> <span>Invalid entry.</span>
            </div>
            <p class="serialModal__message js-modal-message">Items have been sent. Please check your mailbox in game.</p>
            <button type="button" class="serialModal__btn js-modal-btn">Close</button>
        </div>
    </div>

我试过了:

get_confirmation_text = browser.find_element_by_class_name("serialModal__notes")
get_confirmation_text = browser.find_element_by_css_selector("p.serialModal__message")

两者都返回:

<selenium.webdriver.remote.webelement.WebElement (session="1cfb4703be7e4c828a4c24d0ce1254a9", element="239dfa43-0408-4778-8f21-0ac93dad56c7")>

我想在打印声明中看到Invalid coupon code

我的代码:

# coding: utf-8
from selenium import webdriver
import time

edge_options = {
    "executable_path": "/Users/aatang/Desktop/edgedriver_mac64/msedgedriver",
    # ofcourse change path to driver you downloaded.
    "capabilities": {
        "platformName": 'mac os x',  # I get this from Chrome driver's capabilities
        # "os" : "OS X", # also ok.
    }
}

browser = webdriver.Edge(**edge_options)
browser.get('https://kstory.hangame.com/en/index')

select_server = browser.find_element_by_css_selector(
    "span[class='js-selected-text']")

select_server.click()
browser.find_element_by_xpath(
    "//ul[@data-type='server']/li[text()='Conquest(US)']").click()

input_id = browser.find_element_by_name("monarch")
input_code = browser.find_element_by_name("serialcode")
input_id.send_keys("shushu1")
input_code.clear()
input_code.send_keys("191Sept")

submit = browser.find_element_by_xpath('/html/body/main/form/button')
submit.click()

message = browser.find_element_by_xpath("//div[@class='serialModal']/p").text
print(message)

提前致谢

【问题讨论】:

  • 您使用的用户名和优惠券代码是什么?
  • 代码1天后过期,也可以放任意随机字符。服务器:Worlord(SEA),ID:shushu1,代码:30chikisa

标签: python selenium


【解决方案1】:

看看这是否有效

message = driver.find_element_by_xpath("//div[@class='serialModal']/p").text
print(message)

【讨论】:

  • 它不返回任何东西。添加了我的代码块。
猜你喜欢
  • 2022-08-15
  • 2021-05-12
  • 2022-12-13
  • 1970-01-01
  • 1970-01-01
  • 2011-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多