<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.button{
    #44444;
}
</style>
<meta charset="utf-8">
<title>元素定位</title>
</head>
<body>
<a href="https://cloud.fin-shine.com/"> about fin-shine</a>
<button id="okid" name="btnok" class="button" onclick="window.location.herf='https://cloud.fin-shine.com/'">goto fin-shine</button>
</body>
</html>
 
from selenium import webdriver

driver = webdriver.Firefox()   # Firefox浏览器
driver.find_element_by_id("okid").click() #根据属性id定位
driver.find_element_by_name("btnok").click() #根据属性name定位
driver.find_element_by_tag_name("button").click()#搜索到的元素通常不止一个,标签名称来定位元素
driver.find_element_by_class_name("button").click() #class 来定位
driver.find_element_by_link_text("about fin-shine") #超文本链接
driver.find_element_by_partial_link_text("about") #部分超文本定位
posted on 2021-02-03 10:52  open-open  阅读(20)  评论(0)    收藏  举报