web页面组成之html

一、元素定位

为什么要进行元素定位?

因为我们想去操作页面当中的元素、点击、输入

8种定位元素的方式,得到的是一个WebElement的对象

id

name

class_name

link_text:超链接的文本,只能用来定位a标签

partial_link_text:可根据超链接的部分文本进行定位

tag_name

xpath

css_selector

# 运用

driver.find_element_by_id()

driver.find_element_by_name()

driver.find_element_by_class_name()

driver.find_element_by_link_text()

driver.find_element_by_partial_link_text()

driver.find_element_by_tag_name()

driver.find_element_by_xpath()

driver.find_element_by_css_selector()

或者 driver.find_element("id","q")等

# 获取元素的标签名

element.tag_name

# 属性、方法

#输入内容

element.send_keys("王者荣耀")

# 将输入框中的内容清空

element.clear()

#提交

element.submit()

#点击

element.click()

# 属性:父元素,或者其他的

element.parent

element.tagname

element.text

element.get_attribute()

二、find_element与find_elements有什么区别

1、find_element得到的是一个WebElement对象,只会返回查找到的第一个元素,如果找不到,会报错,NoSuchElementException。

2、find_elements得到的是一个列表,会找到所有符合条件的元素,如果找不到,会返回一个空列表。

当我们想判断某个元素存不存在时以下处理:

第一种方法:

if driver.find_elements(By.name,'w'):

  print("元素存在")

else:

  print("元素不存在")

第二种:

try:

  driver.find_element(By.XPATH,'//input[@class="xwd"]')

  print("元素存在")

except:

  print("元素不存在")

二、html的组成

HTML全名(HyperText Markup Language超文本标记语言)是一种用于创建网页的标准标记语言,常常和CSS js一起使用来构建漂亮的页面

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录界面</title>
</head>
<body>
<form action="http://api.lemonban.com/futureloan/member/login" method="POST">
用户名:<input name="username" type="text" placeholder="username">
密码:<input name="password" type="password" placeholder="password">
<input name="submit" type="submit">
</form>
</body>
</html>
标签

  html head body form

属性 :

  -属性名:lang charset action method name ...

  -属性值:"en" "UTF-8"...

  属性的作用:能让一个标签增强某种能力

text

  文本,如“用户名”

内嵌标签

  form 标签嵌套在body标签里面

  input标签嵌套在form标签里面

三、常见HTML标签

p、h1~h6、div、span、a、img、iframe、input、text、password、checkbox、radio、file、select、form

<input type="radio" name="favor_singer">周杰伦

<input type="radio" name="favor_singer">林俊杰

<input type="radio" name="favor_singer">阿然

要实现单选的时候input标签的name需要一致

input标签通常有name属性和value属性

iframe可内嵌网页


四、常见HTMl属性

id、name、class_name、value、readonly、disabled、checked、placeholder

五、CSS

伪元素

h4::before {

  content:"Hello"

}

在h4标签的前面加上了“Hello”

 

posted @ 2021-04-04 23:22  %女王%  阅读(109)  评论(0编辑  收藏  举报