jquery - 无法使用 xpath 定位人体部位图像的元素

标签 jquery html css selenium xpath

我正在使用 driver.findElement(By.xpath(".//*[@id='bodyPartContainer']/div[1]")).click(); 选择一个人体图像的一部分,并且在 webdriver 中低于异常

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":".//*[@id='bodyPartContainer']/div[1]"}

<head>

    <body style="height: 100%">
        <div class="container-fluid">
            <div class="row">
                <!-- Name-->
                <div class="row rowTop">
                    <!-- Email -->
                    <div class="row rowTop">
                        <!-- Date of Birth-->
                        <div class="row rowTop">
                            <!-- Human Body Selection -->
                            <form id="vForm" class="form-horizontal" role="form" data-toggle="validator" novalidate="true">
                                <!-- Type of Request -->
                                <div class="row rowTop">
                                    <!-- Description-->
                                    <div class="row rowTop">
                                        <!-- Human Body -->
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="col-md-3">
                                                    <div id="bodyPartContainer" style="margin-top: 30px; display: block;">
                                                        <div class="humanBodyPart">Head</div>
                                                        <div class="humanBodyPart">Eyes</div>
                                                        <div class="humanBodyPart">Nose</div>
                                                        <div class="humanBodyPart">Mouth</div>
                                                        <div class="humanBodyPart">Chin and Jaw</div>
                                                        <div class="humanBodyPart">Ears</div>
                                                    </div>
                                                </div>
                                                <div class="col-md-3">
                                                </div>
                                                <!-- Files -->
                                                <div class="row" style="margin-top:10px">
                                                    <!-- File -->
                                                    <div class="row" style="margin-top:20px">
                                                        <!-- checkBox 1 -->
                                                        <div class="row rowTop">
                                                            <!-- checkBox 2 -->
                                                            <div class="row rowTop">
                                                                <!-- Submit Btn -->
                                                                <div class="row rowTop" style="margin-top:20px; margin-bottom:30px">
                            </form>
                            </div>
                            <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                <script type="text/javascript">
                                    $(init);
                                    pageUtil.url = "http://52.163.121.157:8080/Curis/";
                                    var box = new BlackBox();
                                    var editor;
                                    var userName = "test 2";
                                    var userEmail = "sidsri133196@gmail.com";
                                    var userDob = "2017-02-09";
                                    var selectedFiles = [];

                                    function initHumanBodySelector() {
                                        var list = [{}, {}, {}] $("#symptomContainer").empty();
                                        $("#bodyPartContainer").empty();
                                        $("#humanBody").empty();
                                        $("#humanBody").humanBodySelector({
                                            gender: $("#selectGender").val(),
                                            callback: null,
                                            basePath: pageUtil.url,
                                            symptomContainer: $("#symptomContainer"),
                                            bodyPartContainer: $("#bodyPartContainer")
                                        });
                                    }

                                    function g_AjxUploadImg(btnImg) {
                                        var button = btnImg,
                                            interval, fileType;
                                        new AjaxUpload(button, {
                                                    type: "POST",
                                                    action: getDataFromBack("getFsAdd", null, "file"),
                                                    name: 'upload[]',
                                                    data: {
                                                        cmd: 'upload',
                                                        target: 'C_',
                                                        nameAppendix: getTimeString()
                                                    },
                                                    datatype: 'JSON',
                                                    onChange: function(file, ext) {
                                                        fileType = ext;
                                                    },
                                                    onSubmit: function(file, ext) {
                                                            if (!(ext && /^(jpg|JPG|png|PNG|gif|GIF|pdf|PDF|doc|DOC|docx|DOCX)$/.test(ext))) { //alert(ext); return false; } }, onComplete:function(file, response) { var result=parseJson(response); debug(result); var fileHash=result.added[0].hash; var fileName=result.added[0].name; var param={}; param.fileHash=fileHash; fileAddress=getDataFromBack("generateFileAddressFromHash",param,"file"); $("#fileDownload").append('' +' <div class="fileBlk" id="file'+fileHash+'">' +'<i class="fa fa-file-o" style="font-size:45px;margin-top:13px"></i>' +'<h6 style="margin-top:4px">'+fileName+'</h6>' +'</div>'); $("#file"+fileHash).click(function(){ $("#fileViewFrame").attr("src",fileAddress); $("#myModal").modal("show"); }); selectedFiles.push(fileHash); //alert(url); //alert(url); }, error:function(data) { alert(data.status); } } ); } function getFileDetailsByFileHashArr(fileHashArr){ var fileDetailArr=[]; if(!isVarValid(fileHashArr)||!(fileHashArr instanceof Array)||fileHashArr.length==0){ return fileDetailArr; } for(var index in fileHashArr){ var param={}; param.fileHash=fileHashArr[index]; var fileDetail=getDataFromBack("getFileDetailByHash",param,"file"); fileDetailArr.push(parseJson(fileDetail)); } return fileDetailArr; } function init(){ $("#name").text(userName); $("#email").text(userEmail); $("#dob").text(userDob); $("#titleLabel").text("Request Appointment Form"); //$("#submit").bind("click",submit); $("#checkBox1").bind("click",checkBox1); $("#checkBox2").bind("click",checkBox2); $('#vForm').validator(); g_AjxUploadImg($("#file")); $('#vForm').validator().on('submit', function (e) { if (e.isDefaultPrevented()) { // handle the invalid form... debug("prevent!!!"); } else { // everything looks good! debug("good!"); submit(); e.preventDefault(); return false; } }); initHumanBodySelector(); } function checkBox1(){ var checkBox1=$("#checkBox1").val(); if(checkBox1==0){ $("#checkBox1").val("1"); }else{ $("#checkBox1").val("0"); } } function checkBox2(){ var checkBox2=$("#checkBox2").val(); if(checkBox2==0){ $("#checkBox2").val("1"); }else{ $("#checkBox2").val("0"); } } function submit(){ var checkBox1=$("#checkBox1").val(); var checkBox2=$("#checkBox2").val(); if(checkBox1==0||checkBox2==0){ box.alert("You must be agree with our conditions",emptyFunc); }else{ var param={}; param.type=$("#selectAppType").val(); param.description=$("#description").val(); param.conditions=json2String(healthConditions); param.fileHashArr=json2String(selectedFiles); box.load("submit",emptyFunc); asyncDataFromBack(afterSubmit,"applyForAppointment",param,"appointment") } } function afterSubmit(data, status){ box.ready("submit"); if(status==ReturnData.success){ box.alert("Success!", function(){ parent.frameGoTo("index/toIndex.action"); }); }else{ box.alert("Error Occured: "+data, emptyFunc); } } function back(){ goTo("appointment/makeAppointment.action"); }
                                </script>
                                <canvas id="firebugCanvas" class="firebugResetStyles firebugBlockBackgroundColor firebugCanvas" width="1366" height="440" style="display: none ! important;" />
                                <div class="mapster_tooltip" style="border: 2px solid black; background: rgb(238, 238, 238) none repeat scroll 0% 0%; width: 160px; padding: 4px; margin: 4px; box-shadow: 3px 3px 5px rgb(83, 83, 83); border-radius: 6px; opacity: 0.9; display: block; position: absolute; left: 198px; top: 693.6px; z-index: 9999;" data-opacity="0.9">Abdomen</div>
                                <div class="firebugResetStyles firebugBlockBackgroundColor" style="left: 689.5px ! important; top: 35.6px ! important; width: 307.25px ! important; height: 46px ! important; border-radius: 18px ! important; box-shadow: 0px 0px 2px 2px highlight ! important;">
    </body>

</html>

谁能帮我解决这个问题。谢谢。

最佳答案

我认为这是因为您缺少指定元素标记的 xpath 部分。

代替 .//[@id='bodyPartContainer']/div[1] 试试 .//div[@id='bodyPartContainer']/div[1].

.//*[@id='bodyPartContainer']/div[1] 也可以(如果您想通配元素类型)。

关于jquery - 无法使用 xpath 定位人体部位图像的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42702935/

相关文章:

javascript - 仅在调整窗口大小时触发可移动分页

javascript - 制作一个不序列化 javascript 的一对多表单 html

html - Internet Explorer 8 忽略 'display: table-cell' 元素的宽度

html - 我想在 Express.js 中渲染静态 html,但仍然有 app.get() 逻辑方法

javascript - Flexbox 在 anchor 内生长

html - 为什么 after 伪元素在 firefox 中绝对定位时会移动一个额外的像素?

javascript - 使用 jquery 添加 CSS

javascript - jAlert 可以指向任何链接吗?

javascript - 我有一个关于 live 方法的问题

javascript - 如何检查是否有空值(Jquery)?