def openCityNews(driver):
indexPage=Index(driver)
newsPage=indexPage.gotoNews(*indexPage.goToNews)
windows=indexPage.getWindowHandles()
newsPage.switchToWindow(windows[-1])
time.sleep(1)
newsPage.scrollToBotton()
time.sleep(2)
newsPage.scrollToElemet(*newsPage.intoCityChois)
jstr = "document.querySelector('#change-city').click()"
newsPage.click_by_js(jstr)
# 随机点击一个省或直辖市
ojstr=str(random.randint(1,32))
newsPage.city[1]=newsPage.city[1]+ojstr+"]"
print(newsPage.city)
newsPage.click(*newsPage.city)
time.sleep(2)
subCityIsExist=newsPage.isElementExist(*newsPage.subCity1)
ojstr1 = str(random.randint(1, 10))
newsPage.otherSubCity[1] = newsPage.otherSubCity[1] + ojstr1 + "]"
otherSubCityIsExist = newsPage.isElementExist(*newsPage.otherSubCity)
if subCityIsExist:
if otherSubCityIsExist:
newsPage.click(*newsPage.otherSubCity)
time.sleep(2)
else:
newsPage.click(*newsPage.subCity1)
time.sleep(2)
indexPage.closeWindowNotIndex()
indexPage.switchToWindow(windows[0])
调用的时候 for循环下 概率性能点到各个1,2级城市的新闻