Python Selenium - how to get confirmation after submit

2024/10/5 19:15:31

I have a follow up question on this post, I want to get any confirmation text after I hit submit button. Either the code works or not.

html - invalid example

<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 - gift sent example

<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>

enter image description here

And I tried:

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

Both return:

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

I would like to see Invalid coupon code in print statement.

My Code:

# coding: utf-8
from selenium import webdriver
import timeedge_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)

Thanks in advance

Answer

See if this works

message = driver.find_element_by_xpath("//div[@class='serialModal']/p").text
print(message)
https://en.xdnf.cn/q/119539.html

Related Q&A

Assigning a input on a line to its line number?

I was having a go at the following problem from the AIO (Australian Informatics Olympiad) Training Problems Site (Question in Italics and specifics in bold, my attempt below): The Problem Encyclopaedia…

Create a new list according to item value

I have a list like below. [T46, T43, R45, R44, B46, B43, L45, L44, C46, C45]where I want to group according to int value:[id][ , , , , ] # AREA PATTERN [Top, Right, Bottom, Left, Center][46][1,0,1…

Concatenating many time and date columns

I have many date and time column pairs (around 15 each) that share the same prefix, ie. SH or DEL. The columns are all of dtype object, ie. string. All the columns belong to the same Dataframe. Here is…

Python with ICS files and CSV [duplicate]

This question already has answers here:Parsing files (ics/ icalendar) using Python(6 answers)Closed 5 years ago.one friend ask me some help on a personnal project, but I have to admit my skills in Pyth…

loading my data in numpy genfromtxt get errors

I have my data file contain 7500 lines with :Y1C 1.53 -0.06 0.58 0.52 0.42 0.16 0.79 -0.6 -0.3 -0.78 -0.14 0.38 0.34 0.23 0.26 -1.8 -0.1 -0.17 0.3…

Install dlib with cuda support ubuntu 18.04

I have CUDA 9.0 and CUDNN 7.1 installed on Ubuntu 18.04(Linux mint 19). Tensorflow-gpu works fine on GPU(GTX 1080ti).Now i am trying to build dlib with CUDA support:sudo python3 setup.py install --yes …

View 3 dimensional Numpy array in Matplotlib and taking arguments from Keyboard or mouse

I have 3 dimensional data say (5,100,100). Now I would like to see them slice by slice upon hitting the down arrow button.

python default argument syntax error

I just wrote a small text class in python for a game written using pygame and for some reason my default arguments arent working. I tried looking at the python documentation to see if that might give m…

Variable not defined (Python)

FlightType=input("Which flight would you like to fly? Type 2 Seater, 4 Seater, or Historic.") # No validation included for the inputFlightLen=input("Would you like to book the 30 minu…

PyGame: draw.rect() has invalid parameters

Im trying to learn mouse events with PyGame, and Im trying to draw a box wherever the user clicks. Im setting a variable equal to pygame.mouse.get_pos(), and calling individual tuple members according …