selenium test can not locate the page elements, you may have the following reasons

1, to complete the element is not loaded, a waiting time can be set

2, if the iframe element, the element can not be found looking in the window, it is not clickable. Therefore, to switch to find the iframe element.

driver.switch_to_frame ( "frameName") # The name switched frame

driver.switch_to_frame("frameName.0.child")  # 子框架

driver.switch_to_default_content()  # 返回

3, click on the elements to be covered, instead of using click enter

driver.find_element_by_css_selector("div.loginForm>input#loginBtn").send_keys(Keys.ENTER)

4, not in the window, you need to pull the scroll bar, as follows

A. Let the scroll bar to the specified element location

menu = driver.find_element_by_css_selector(".nav")

hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1")

ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()

B. try the drop-down period of the scroll bar, so that button to see

js = "window.scrollTo(100,450)"

driver.execute_script(js)

driver.find_element_by_css_selector("div.loginForm>input#loginBtn").click()

Guess you like

Origin www.cnblogs.com/pinktest/p/11610479.html