在定位元素时,不太适合直接使用chrome的copy xpath, 这种复制方式如下
//*[@id="AA"]/div[2]/div[1]/div/div/div[1]/div/div/span/p
这样的话 ,如果页面稍微调整, 就可能导致上面的方式定位不到我们想要的元素,就需要换一些方式。
以下是自己的总结, 尝试,确定可行,例子如下:
<span id="cke_1_top" class="cke_top cke_reset_all" role="presentation" style="height: auto; user-select: none;"><span id="cke_8" class="cke_voice_label">Editor toolbars</span><span id="cke_1_toolbox" class="cke_toolbox" role="group" aria-labelledby="cke_8" onmousedown="return false;"><span id="cke_9" class="cke_toolbar" aria-labelledby="cke_9_label" role="toolbar"><span id="cke_9_label" class="cke_voice_label">Insert</span><span class="cke_toolbar_start"></span><span class="cke_toolgroup" role="presentation"><a id="cke_10" class="cke_button cke_button__bold cke_button_off" href="javascript:void('Bold')" title="Bold (Ctrl+B)" tabindex="-1" hidefocus="true" role="button" aria-labelledby="cke_10_label" aria-describedby="cke_10_description" aria-haspopup="false" onkeydown="return CKEDITOR.tools.callFunction(1,event);" onfocus="return CKEDITOR.tools.callFunction(2,event);" onclick="CKEDITOR.tools.callFunction(3,this);return false;"><span class="cke_button_icon cke_button__bold_icon" style="background-image:url('https://csdnimg.cn/release/blog_editor_html/release1.4.4/ckeditor/plugins/icons.png?t=J7K9');background-position:0 -128px;background-size:auto;"> </span><span id="cke_10_label" class="cke_button_label cke_button__bold_label" aria-hidden="false">Bold</span><span id="cke_10_description" class="cke_button_label" aria-hidden="false">Keyboard shortcut Ctrl+B</span></a><a id="cke_11" class="cke_button cke_button__italic cke_button_off" href="javascript:void('Italic')" title="Italic (Ctrl+I)" tabindex="-1" hidefocus="true" role="button" aria-labelledby="cke_11_label" aria-describedby="cke_11_description" aria-haspopup="false" onkeydown="return CKEDITOR.tools.callFunction(4,event);" onfocus="return CKEDITOR.tools.callFunction(5,event);" onclick="CKEDITOR.tools.callFunction(6,this);return false;"><span class="cke_button_icon cke_button__italic_icon" style="background-image:url('https://csdnimg.cn/release/blog_editor_html/release1.4.4/ckeditor/plugins/icons.png?t=J7K9');background-position:0 -384px;background-size:auto;"> </span><span id="cke_11_label" class="cke_button_label cke_button__italic_label" aria-hidden="false">Italic</span><span id="cke_11_description" class="cke_button_label" aria-hidden="false">Keyboard shortcut Ctrl+I</span></a><a id="cke_12" class="cke_button cke_button__underline cke_button_off" href="javascript:void('Underline')" title="Underline (Ctrl+U)" tabindex="-1" hidefocus="true" role="button" aria-labelledby="cke_12_label" aria-describedby="cke_12_description" aria-haspopup="false" onkeydown="return CKEDITOR.tools.callFunction(7,event);" onfocus="return CKEDITOR.tools.callFunction(8,event);" onclick="CKEDITOR.tools.callFunction(9,this);return false;"><span class="cke_button_icon cke_button__underline_icon" style="background-image:url('https://csdnimg.cn/release/blog_editor_html/release1.4.4/ckeditor/plugins/icons.png?t=J7K9');background-position:0 -576px;background-size:auto;"> </span><span id="cke_12_label" class="cke_button_label cke_button__underline_label" aria-hidden="false">Underline</span><span id="cke_12_description" class="cke_button_label" aria-hidden="false">Keyboard shortcut Ctrl+U</span></a><a id="cke_13" class="cke_button cke_button__strike cke_button_off" href="javascript:void('Strikethrough')" title="Strikethrough" tabindex="-1" hidefocus="true" role="button" aria-labelledby="cke_13_label" aria-describedby="cke_13_description" aria-haspopup="false" onkeydown="return CKEDITOR.tools.callFunction(10,event);" onfocus="return CKEDITOR.tools.callFunction(11,event);" onclick="CKEDITOR.tools.callFunction(12,this);return false;"><span class="cke_button_icon cke_button__strike_icon" style="background-image:url('https://csdnimg.cn/release/blog_editor_html/release1.4.4/ckeditor/plugins/icons.png?t=J7K9');background-position:0 -448px;background-size:auto;"> </span><span id="cke_13_label" class="cke_button_label cke_button__strike_label" aria-hidden="false">Strikethrough</span><span id="cke_13_description" class="cke_button_label" aria-hidden="false"></span></a><a id="cke_14" class="cke_button cke_button__h1 cke_button_off" href="javascript:void('h1')" title="h1 (Ctrl+1)" tabindex="-1" hidefocus="true" role="button" aria-labelledby="cke_14_label" aria-describedby="cke_14_description" aria-haspopup="false" onkeydown="return CKEDITOR.tools.callFunction(13,event);" onfocus="return CKEDITOR.tools.callFunction(14,event);" onclick="CKE