关于相对定位器,Selenium官网文档的介绍
介绍了五种相对定位器:
above, below, left of, right of, near
并给出了例子:
email_locator = locate_with(By.TAG_NAME, "input").above({
By.ID: "password"})
其中相对定位器(relative locator)方法(此处即above()
),参数既可以传元素对象也可以传locator。官网的例子统一只用了locator,直接传一个之前定位好的element也是可以的:
origin_element = driver.find_element(By.ID, "password")
email_locator = locate_with(By.TAG_NAME, "input").above(origin_element