我使用xpath的代码,但无法点击它并选择下拉元素。我尝试从键盘按键击选择下拉列表,但似乎这也无效。
driver.findElement(By.xpath(".//*[@id='div_poi_type']/span[2]/span/span[1]")).click()
<document>
<html class="k-ff k-ff43" lang="en">
<head>
<body onload="loadKUnMask();tempLoadKUnMask();">
<meta charset="utf-8"/>
<title>Uniserve</title>
<meta content="width=ddffdvice-width, initial-scale=1.0, maximum-scale=1.0" name="viewport"/>
<meta content="" name="ddffdscription"/>
<meta content="ThemeBucket" name="author"/>
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<meta content="IE=EmulateIE11" http-equiv="X-UA-Compatible"/>
<meta content="IE=11" http-equiv="X-UA-Compatible"/>
<!-- <link rel="shortcut icon" href="#" type="image/png">-->
<link rel="stylesheet" href="http://abc.xyzdfff.lml.com:80/obstatic/OB/css/font-awesome.css"/>
<link rel="stylesheet" href="http://abc.xyzdfff.lml.com:80/obstatic/OB/css/style.css"/>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]> <script src="http://abc.xyzdfff.lml.com:80/obstatic/OB/js/html5shiv.js"></script> <script src="http://abc.xyzdfff.lml.com:80/obstatic/OB/js/respond.min.js"></script> <![endif]-->
<!-- Kendo CSS -->
<link href="http://abc.xyzdfff.lml.com:80/obstatic/OB/css/kendo/kendo.common-material.min.css" rel="stylesheet"/>
<link href="http://abc.xyzdfff.lml.com:80/obstatic/OB/css/kendo/kendo.material.min.css" rel="stylesheet"/>
<link href="http://abc.xyzdfff.lml.com:80/obstatic/OB/css/kendo/kendo.dataviz.min.css" rel="stylesheet"/>
<link href="http://abc.xyzdfff.lml.com:80/obstatic/OB/css/kendo/kendo.dataviz.material.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="http://abc.xyzdfff.lml.com:80/obstatic/OB/css/ob_styles.css"/>
<link rel="stylesheet" href="http://abc.xyzdfff.lml.com:80/obstatic/OB/css/style-plugins.css"/>
<link rel="stylesheet" href="http://abc.xyzdfff.lml.com:80/obstatic/OB/css/bootstrap-datetimepicker.css"/>
<div id="kendo-mask" style="display: none;">
<div id="temp-kendo-mask" style="display: none;">
<!--body wrapper start-->
<div class="col-sm-12 marginbottom40">
<div class="wrapper1">
<div class="panel-body documentviebg">
<div class="breadcrumtxt">
<div class="clear"/>
<div class="panel panel-widget padreduce">
<ul class="panel-tools panel-tools-hover margbtm">
<div class="clear"/>
<div class="row clearfix mainsection">
<div class="">
<!--<div class="heading">-->
<h1 class="inlineblock marginleft20">Inbox</h1>
<div class="topmenudrop">
<a class="app_fields" data-toggle="modal" href="#App_fields" title="Mobile app fields">View mobile app fields</a>
<hr class="breadcrumthr"/>
<!-- </div>-->
<div id="txt"/>
<div class="clear mrg25T"/>
<div class="col-md-12">
<div class="padingleftright10">
<div id="FirstSrc" class="col-md-9 pad10L">
<div id="rigthDataEntryTab" class="col-md-3">
<div id="resizeDiv" class="resizebg"/>
<div class="imgboxbr">
<div class="imghdbg">
<div class="dataentryInputs">
<form id="ddffdForm" class="form-borddffdred" onsubmit="return false;" name="ddffdForm" method="post" action="#">
<div class="ddffdmo-section k-content">
<ul id="panelbar" class="k-widget k-reset k-headdffdr k-panelbar" data-role="panelbar" tabinddffdx="0" role="menu">
<li class="k-state-active k-item k-first k-state-highlight" role="menuitem" aria-expanddffdd="true" aria-hidddffdn="false">
<li class="k-state-active k-item k-state-highlight" role="menuitem" aria-expanddffdd="true" aria-hidddffdn="false">
<span class="k-link k-headdffdr">
Proof of Iddffdntification
<span class="k-icon k-i-arrow-n k-panelbar-collapse"/>
</span>
<div class="dataentryBlock k-content" role="region" aria-hidddffdn="true" style="display: block;">
<div id="div_poi_type" class="form-group">
<label>Type</label>
<span class="red">*</span>
<span class="k-widget k-dropdown k-headdffdr form-control" style="" title="Type" unselectable="on" role="listbox" aria-haspopup="true" aria-expanddffdd="false" tabinddffdx="0" aria-owns="poi_type_listbox" aria-disabled="false" aria-readonly="false" aria-busy="false">
<span class="k-dropdown-wrap k-state-ddffdfault k-state-hover" unselectable="on">
<span class="k-input" unselectable="on">Select From List</span>
<span class="k-select" unselectable="on">
<span class="k-icon k-i-arrow-s" unselectable="on">select</span>
</span>
</span>
<select id="poi_type" class="form-control" title="Type" data-role="dropdownlist" style="display: none;">
<option value="" selected="selected">Select from list</option>
<option value="Z00014">Address Card with Photo issued by ddffdpartment of Post</option>
<option value="Z00007">Arms License</option>
<option value="Z00016">Bank Passbook With Photo (Schedule Bank / Post Office)</option>
<option value="Z00064">Medical Council Iddffdntity card</option>
<option value="Z00065">Other Government Certificate</option>
<option value="FS0002">Passport (Indian)</option>
</select>
</span>
</div>
&#13;
答案 0 :(得分:0)
尝试将“unselectable”属性的值更改为“off”,例如使用JavascriptExecutor类将其取消选择=“off” -
WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementByID('//id of element').setAttribute('unselectable', 'off')");
然后选择webelement的值。
答案 1 :(得分:0)
以下是您的问题的答案:
如HTML DOM
所示,要点击DropDown
和Select
选项Passport (Indian)
,您可以考虑使用以下代码块:
WebElement drop_down = driver.findElement(By.id("poi_type"));
Select drop_down_element = new Select(drop_down );
drop_down_element.selectByValue("FS0002");
如果这回答你的问题,请告诉我。