Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97841

How to check if URL contains something

$
0
0

I'm making a program which goes to a url, clicks a button, checks if the page gets forwarded and if it does saves that url to a file.

However, after a couple of entries the page blocks you from doing anything. When this happens the URL changes and you'll get this Block.aspx?c=475412

Now how'd I be able to check if the url contains Block.aspx?c=475412 after each try? I've tried looking for this but I could only find people asking how to get the current URL, not what I'm looking for, I need to check what the url contains.

Here is my code.

import selenium
from selenium import webdriver


url_list = open("path')

try:
    driver = webdriver.Chrome("C:\\python\\chromedriver")
    for url in url_list:
       driver.get(url)
       send = driver.find_element_by_id("NextButton")
       send.click()

       if (driver.find_elements_by_css_selector("a[class='Error']")):
          print("Error class found")


except ValueError:
    print("Something went wrong checking the URL.")

I suppose I'd add an if statement checking if the URL contains Block.aspx?c=475412, if anyone would be able to help me out I'd greatly appreciate it.


Viewing all articles
Browse latest Browse all 97841

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>