进行语法校正
因此,有一个网站由JavaScript生成。并每秒更新。我想每秒获得值。但是该网站会弹出一个模态,询问"您还在这里吗"。然后您需要单击按钮。所以首先我的代码看起来像这样:
try:
button = browser.find_elements_by_xpath("//button[contains(@value, 'Refresh Page')]");
button.click()
rounds = rounds+1
except:
rounds = rounds+1
但是,当我查看浏览器时,它仍然每发重新加载,甚至在屏幕上都不会显示。
我该如何完成此工作,仅在屏幕上单击按钮?谢谢!
遍历以下代码以单击该按钮,可见并可以刷新页面
button = browser.find_elements_by_xpath("//button[contains(@value, 'Refresh Page')]");
//To check button is present on page
if (len(button)>0):
//And is displayed
if button[0].is_displayed():
button[0].click()
else:
print "button not display"
else:
print("there is not refresh page button")
或
// to check the dialog present here "show" is the class which retain by the div once the refresh button get enabled
if "show" in browser.find_element_by_id('timeout_dialog').get_attribute('class'):
browser.find_element_by_xpath("//button[contains(@value, 'Refresh Page')]").click()
else:
print "refresh button not displaying"
注意:按Python