使用硒和python,我想知道网站是否有一个特定的字符串,如果它打印是,或者如果它不打印否



我目前正在进入一个网站,并使用网站搜索栏来搜索查询列表,该网站然后返回该查询是否可用或不可用字符串。我希望能够搜索查询,然后检查查询是否可用。

try:
nres = driver.find_elements_by_id(str("nres"))
if nres ==
print("Tag is unavailable")
except NoSuchElementException:
print("Tag is available")

这段代码可能会对您有所帮助。

from selenium import webdriver
import time
driver = webdriver.Chrome(executable_path="path")
driver.implicitly_wait(6)
driver.maximize_window()
driver.get("https://www.gamertagavailability.com/check.php")
driver.find_element_by_id("mytag").send_keys("Sampletext")
driver.find_element_by_id("doitnow").click()
time.sleep(2)
check = driver.find_element_by_xpath("//div[@id='nres']/p[2]").text
if check == "is not available!":
print("Tag is not available")
else:
print("Tag is available")
time.sleep(2)
driver.quit()

你可以在下面检查一下,我已经使用explicitWait在输入框中输入值并点击按钮。

driver.get("https://www.gamertagavailability.com/")
gamerTags=WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.ID,"mytag")))
gamerTags.send_keys("GameZoneOwner")
checkNowBtn =WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,"doitnow")))
checkNowBtn.click()
#I have taken the common XPath for the status as it's ID is different and verified for both the status.
status = driver.find_element_by_xpath("//div[@id='test']/div//p[2]").text
if status == "seems to be available!":
print("The tag is available ")
elif status == "is not available!":
print("Tag is not available")

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

相关内容

最新更新