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