把input的name属性显示在输入框左侧
时间: 2023-04-01 20:03:24 浏览: 139
可以使用HTML的label标签来实现这个功能,代码如下:
<label for="inputName">姓名:</label>
<input type="text" id="inputName" name="name">
相关问题
怎么把标题设置在输入框左边?
在网页设计中,如果你想要将标题放在输入框的左侧,通常会使用CSS布局技巧来实现,比如Flexbox或者Grid布局。特别是对于简单的布局,你可以使用`<label>`标签配合`for`属性来关联输入框(`<input>`),这样点击标签时,输入框会被选中。示例代码如下:
```html
<label for="myInput">输入框标题</label>
<input type="text" id="myInput" name="myInput">
```
在这个例子中,"输入框标题" 就是你的标题,它会默认位于`<input>`元素的左边。
如果你想让标题完全独立于输入框,可以考虑使用`<div>`包裹它们,然后使用CSS调整样式,比如设置`float`, `display: flex` 或者 `position: relative` 和 `left` 属性来移动标题。
```html
<div>
<span>输入框标题</span>
<input type="text" id="myInput" name="myInput">
</div>
<style>
.title-input {
display: flex;
}
.title-input span {
margin-right: 10px; /* 根据需要调整间距 */
}
</style>
```
(1)从Selenium中引入WebDriver; (2)引入unittest; (3)引入ddt; (4)引入步骤1中的csvv01.py里面的数据读取的方法 (5)使用Selenium模块的WebDriver打开谷歌浏览器; (6)在谷歌浏览器中通过get方法发送网址打开资产管理系统登录页面; (7)增加智能时间等待5秒; (8)查看登录页面中的用户名输入框元素,通过id属性定位用户名输入框,并输入用户名student; (9)查看登录页面中的密码输入框元素,通过xpath属性定位密码输入框,并输入密码student; (10)查看登录页面中的登录按钮元素,通过tag_name方法定位登录按钮,使用click()方法点击登录按钮进入资产管理系统首页; (11)在资产管理系统首页查看左侧“品牌”按钮元素,通过link_text方法进行定位,使用click()方法点击“品牌”按钮进入品牌页面; (12)在品牌页面通过xpath方法点击“新增”按钮; (13)通过数据驱动批量输入“品牌名称”和“品牌编码”; (14)通过css_selector方法定位并点击“保存”按钮。
以下是根据您的要求编写的代码:
```
from selenium import webdriver
import time
import unittest
import ddt
from csvv01 import get_data
@ddt.ddt
class TestAssetManagement(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.maximize_window()
self.driver.get("http://10.2.39.8/ams/front/login.do?gotourl=http%3A%2F%2F10.2.39.8%2Fams%2Ffront%2Fasset%2Fasset_list.do")
time.sleep(5)
def tearDown(self):
self.driver.quit()
@ddt.file_data('data.csv')
def test_add_brand(self, data):
username = 'student'
password = 'student'
brand_name = data[0]
brand_code = data[1]
# 输入用户名
username_input = self.driver.find_element_by_id('loginName')
username_input.send_keys(username)
# 输入密码
password_input = self.driver.find_element_by_xpath('//*[@id="password"]')
password_input.send_keys(password)
# 点击登录按钮
login_button = self.driver.find_element_by_tag_name('button')
login_button.click()
# 点击“品牌”按钮进入品牌页面
brand_button = self.driver.find_element_by_link_text('品牌')
brand_button.click()
# 点击“新增”按钮
add_button = self.driver.find_element_by_xpath('//*[@id="content"]/div[2]/div/div[1]/button')
add_button.click()
# 输入品牌名称
brand_name_input = self.driver.find_element_by_id('title')
brand_name_input.send_keys(brand_name)
# 输入品牌编码
brand_code_input = self.driver.find_element_by_id('code')
brand_code_input.send_keys(brand_code)
# 点击保存按钮
save_button = self.driver.find_element_by_css_selector('#submitButton')
save_button.click()
# 断言
self.assertIn(brand_name, self.driver.page_source)
self.assertIn(brand_code, self.driver.page_source)
if __name__ == '__main__':
unittest.main(verbosity=2)
```
其中,我们使用了ddt库来实现数据驱动,从data.csv文件中读取数据。在setUp()方法中,我们使用了time.sleep()方法来实现智能等待。在test_add_brand()方法中,我们使用了各种定位元素的方法来进行操作,并使用了断言来验证测试结果。
阅读全文
相关推荐
















