I’m attempting to check an online portal utilizing Selenium and Python. The issue is, I’m unable to get round an error, in different phrases, I’m unable to catch the alert.
State of affairs:
Seek for a person, if the person is just not discovered, the web site throws an error. I’ve an inventory that comprises legitimate and invalid customers to carry out the search upon. When the search is profitable, there are just a few hyperlinks I have to click on to get to the person. If the person is just not discovered, the hyperlinks will not be displayed and an error is displayed as an alternative. The issue is after I seek for an invalid person, the code is in search of the hyperlinks which can be displayed when the a legitimate person is displayed.
Code:
from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.help.choose import Choose
from selenium.webdriver.frequent.keys import Keys
from selenium.webdriver.help.ui import Choose
from selenium.frequent.exceptions import TimeoutException
from selenium.webdriver.help import expected_conditions as EC
from selenium.webdriver.frequent.alert import Alert
from selenium.frequent.exceptions import NoAlertPresentException
import time
browser = webdriver.Chrome() # sort: WebDriver is Chrome
browser.get("https:URL")
if choice == 'quantity':
nums = ['111', '123', '456']
searchbox = browser.find_element_by_id("searchPattern")
noUser = browser.find_element_by_xpath('//*[@id="includeError"]/div')
strive:
for num in nums:
searchbox.send_keys(num)
browser.find_element_by_xpath('//[@id="User"]/enter[2]').click on()
time.sleep(4)
user_links = ['photos', 'message', 'mails']
for url in user_links:
if url in user_links:
browser.find_element_by_link_text(url).click on()
time.sleep(4)
elif url not in user_links:
print "No customers discovered"
browser.switch_to_window(browser.window_handles[0])
time.sleep(5)
browser.find_element_by_id('searchPattern').clear()
besides noUser:
print "no customers"