1

I have a program with python & selenium. I will print the program like this :

end-bubble bubble ok

end-bubble bubble high

My goals are like this:

ok

high

My idea is to print without the end-bubble bubble only ok or high but I don't know how the script with python selenium.

Please give me solution.

This is my script :

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver = webdriver.Chrome (executable_path=r"C:\Users\rizki.abdillah\Desktop\Selenium\chromedriver.exe")
# maximize with maximize_window()
driver.maximize_window()
driver.get("https://status.cloud.google.com/")
# identify element
service_status = driver.find_elements_by_css_selector("tr>.day.col8>span").get_attribute("class")
print(service_status)
1
  • A more robust test would likely split the string and then verify that the class you're expecting is in the array of strings (i.e. the order of classes in CSS is not important) – ernie Apr 6 at 23:08
1

You can use Python's .split() function. Change the last line of your script to

print(service_status.split(' ')[2])
1

It will depend on what you want to tell in your code.

If you want to remove the text "end-bubble bubble", then you can use replace:

service_status.replace('end-bubble bubble','')

If you want to explicitly only take the last word of the string, you can use deconstruction:

_, _, last = service_status.split()

Or if you want to be more cryptic (don't be please):

service_status.split()[-1]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.