当前位置: 首页 > news >正文

甘南藏族自治州网站建设_网站建设公司_企业官网_seo优化

网站优化推广怎么做,做外链一般都用网站首页吗,爱采购推广平台,企业培训体系硒定位器是处理网页上的元素时的关键。 从ID#xff0c;名称#xff0c;类#xff0c;标记名#xff0c;XPath#xff0c;CSS选择器等定位器列表中#xff0c;可以根据需要选择其中任何一种#xff0c;然后在网页上找到Web元素。 由于与tagName或linktext相比#xff0… 硒定位器是处理网页上的元素时的关键。 从ID名称类标记名XPathCSS选择器等定位器列表中可以根据需要选择其中任何一种然后在网页上找到Web元素。 由于与tagName或linktext相比ID名称XPath或CSS选择器的使用更为频繁因此人们对后者的定位器的了解较少或没有工作经验。 在本文中我将详细介绍Selenium中tagName定位器的用法和实时示例。 那么Selenium中的tagName定位符是什么 tagName是DOM结构的一部分其中页面上的每个元素都是通过标签例如输入标签按钮标签或锚定标签等定义的。每个标签都具有多个属性例如ID名称值类等。就其他定位符而言在Selenium中我们使用了标签的这些属性值来定位元素。 对于Selenium中的tagName定位器我们将仅使用标签名称来标识元素。 以下是LambdaTest登录页面的DOM结构其中我突出显示了标签名称 电子邮件字段 input typeemail nameemail value placeholderEmail requiredrequired autofocusautofocus classform-control mt-3 form-control-lg input typeemail nameemail value placeholderEmail requiredrequired autofocusautofocus classform-control mt-3 form-control-lg 密码栏位 input typepassword namepassword placeholderPassword classform-control mt-3 form-control-lg input typepassword namepassword placeholderPassword classform-control mt-3 form-control-lg 登录按钮 button typesubmit classbtn btn-primary btn-lg btn-block mt-3LOGIN /button button typesubmit classbtn btn-primary btn-lg btn-block mt-3LOGIN /button 忘记密码链接 button typesubmit classbtn btn-primary btn-lg btn-block mt-3LOGIN /button button typesubmit classbtn btn-primary btn-lg btn-block mt-3LOGIN /button 现在想到的问题是何时在Selenium中使用此tagName定位符 好吧在没有属性值如ID类或名称并且倾向于定位元素的情况下您可能不得不依靠在Selenium中使用tagName定位器。 例如如果您希望从表中检索数据则可以使用 td 标记或 tr 标记检索数据。 同样在希望验证链接数量并验证它们是否正常工作的情况下您可以选择通过anchor标签定位所有此类链接。 请注意在一个简单的基本场景中仅通过标签定位元素这可能会导致标识大量值并可能导致问题。 在这种情况下Selenium将选择或定位与您端提供的标签匹配的第一个标签。 因此如果要定位单个元素请不要在Selenium中使用tagName定位器。 通过Selenium中的tagName标识元素的命令是 driver.findElement(By.tagName( input )); 实时场景在Selenium中突出显示tagName定位器 场景1 一个基本的示例我们在LambdaTest的“我的个人资料”部分中找到图像头像 参考是化身的DOM结构 img srchttps://www.gravatar.com/avatar/daf7dc69b0d19124ed3f9bab946051f6.jpg?s200dmmrg altsadhvi classimg-thumbnail 现在让我们看一下代码片段 package Chromedriver; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class Locator_By_Tagname { public static void main(String[] args) throws InterruptedException { // TODO Auto-generated method stub         //Setting up chrome using chromedriver by setting its property //Setting up chrome using chromedriver by setting its property System.setProperty( webdriver.chrome.driver , Path of chromeDriver );                 //Opening browser WebDriver driver new ChromeDriver() ;                 //Opening in maximize mode //Opening window tab driver.manage().window().maximize();                 //Opening application driver.get( https://accounts.lambdatest.com/login );                 //Locating the email field element via Name tag and storing it //Locating the email field element via Name tag and storing it in the webelement WebElement email_fielddriver.findElement(By.name( email ));                 //Entering text into the email field //Entering text into the email field email_field.sendKeys( sadhvisingh24gmail.com );                 //Locating the password field element via Name tag and storing it //Locating the password field element via Name tag and storing it in the webelement WebElement password_fielddriver.findElement(By.name( password ));                         //Entering text into the password field //Entering text into the password field password_field.sendKeys( New1life );                 //Clicking on the login button to login to the application WebElement login_buttondriver.findElement(By.xpath( //button[text()LOGIN] ));                 //Clicking on the login button login_button.click();                 //Clicking on the Settings option driver.findElement(By.xpath( //*[idapp]/header/aside/ul/li[8]/a )).click();                 //Waiting for the profile option to appear Thread. sleep (3500);                 // *[ id app ] /header/aside/ul/li [8] /ul/li [1] /a //Clicking on the profile link driver.findElement(By.xpath( //*[idapp]/header/aside/ul/li[8]/ul/li[1]/a )).click();                 //Locating the element via img tag for the profile picture and storing it in the webelement WebElement image driver.findElement(By.tagName( img ));                 //Printing text of Image alt attribute which is sadhvi System.out.println(image.getAttribute( alt )); } } 方案2 在此示例中我们将验证LambdaTest主页上的链接数并打印这些链接文本 package Chromedriver; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class Tagname_linktest { public static void main(String[] args) { // TODO Auto-generated method stub //Setting up chrome using chromedriver by setting its property //Setting up chrome using chromedriver by setting its property System.setProperty( webdriver.chrome.driver , Path of chromeDriver );                 //Opening browser WebDriver driver new ChromeDriver() ;                 //Opening in maximize mode //Opening window tab driver.manage().window().maximize();                 //Opening application driver.get( https://www.lambdatest.com );                 //storing the number of links in list ListWebElement links driver.findElements(By.tagName( a ));                 //storing the size of the links int i links.size();                 //Printing the size of the string System.out.println(i);                 for (int j0; ji; j) { //Printing the links System.out.println(links.get(j).getText()); }                 //Closing the browser driver.close();                                 } } 下面是控制台的屏幕截图 情况3 在此示例中我将展示何时要标识表中的行数因为在运行时此信息可以是动态的因此我们需要预先评估行数然后检索或验证信息。 下面是表的DOM结构 tbody classyui3-datatable-data tr idyui_patched_v3_18_1_1_1554473988939_130 data-yui3-recordmodel_1 classyui3-datatable-even tr idyui_patched_v3_18_1_1_1554473988939_130 data-yui3-recordmodel_1 classyui3-datatable-even td classyui3-datatable-col-name yui3-datatable-cell John A. Smith /td 1236 Some Street San Francisco CA /td /tr //……更多行继续// 现在让我们看一下其代码片段 package Chromedriver; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; public class Tagname_Row_data { public static void main(String[] args) { // TODO Auto-generated method stub //Setting up chrome using chromedriver by setting its property //Setting up chrome using chromedriver by setting its property System.setProperty( webdriver.chrome.driver , Path of chromeDriver );         //Opening browser WebDriver driver new ChromeDriver() ;         //Opening in maximize mode //Opening window tab driver.manage().window().maximize();         //Opening application driver.get( https://alloyui.com/examples/datatable );         //locating the number of rows of the table ListWebElement rows driver.findElements(By.tagName( tr ));         //Printing the size of the rows System.out.print(rows.size());         //Closing the driver driver.close();                                 } } 控制台输出快照 结论 如您所见我如何在Selenium中的不同情况下使用tagName定位器。 您还可以使用XPath或CSS选择器将tagName定位器与属性值结合使用。 当涉及到其他定位元素的场景时我可能不建议您在Selenium中使用tagName定位器但是上述提到的场景确实可以派上用场。 Selenium中tagName定位器的使用可能受到限制但是如果您希望成为熟练的自动化测试人员 那么了解如何使用tagName定位器以及何时使用它就变得非常关键。 翻译自: https://www.javacodegeeks.com/2019/04/locating-elements-tagname-selenium.html
http://www.ihoyoo.com/news/34695.html

相关文章:

  • 垫江网站建设价格网站建设包括哪些内容
  • 网站开发模板免费下载怎么建立网站网址
  • 网站注册域名位置网站中下滑菜单怎么做
  • 国内外创意网站欣赏用wang域名做购物网站怎么样
  • 四平做网站重庆做网站代运营
  • wp如何做网站地图合肥网站建设哪个好
  • 手机架设网站网站优化个人工作室
  • 网站的收费窗口怎么做网站制作 那种语言好
  • 女人和男人做床上爱网站WordPress插件Discuz
  • 做网站的原理营销qq手机版
  • 莆田做网站公司电话互联网推广运营
  • 深圳网站设计首选刻技术支持网站
  • 成套小说网站模板中国建筑人才培训网
  • 永久免费个人网站注册南宁网页设计培训机构
  • 枣庄建设网站wordpress需要备案号
  • 阿虎手机站常用的系统开发方法有哪些
  • 湖南住房城乡建设厅官方网站wordpress的论坛主题
  • 建网站好还是开天猫好网站开发建设中
  • 广东省水利工程建设信息网站ps软件推荐
  • 系统门户网站建设详细功能网络平台推广案例
  • 做网站需要什么编程语言沈阳网站建设管理
  • seo发布网站最好的网站建设机构
  • 百度山西网站建设和百度推广商城微信网站怎么做
  • 营销型网站建设的五力原则包括专业制作标书
  • 搭建网站需要学什么软件阿里指数在哪里看
  • 网站建设 指标德州建设银行兑换网站
  • 广州建网站兴田德润可信房产公司网站模板
  • 张掖艺能网站建设房地产市场
  • 襄樊网站网站建设自建外贸网站多少钱
  • 网站中单选按钮怎么做查询网站注册信息