Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中使用xpath或cssSelector提取href属性_Java_Xpath_Selenium_Css Selectors - Fatal编程技术网

在Java中使用xpath或cssSelector提取href属性

在Java中使用xpath或cssSelector提取href属性,java,xpath,selenium,css-selectors,Java,Xpath,Selenium,Css Selectors,我正在尝试使用可在selenium中使用的xpath/css表达式从以下锚定标记中提取/store href属性。你能帮我点灯吗 <a href="http://domain/bang?a=3681fd26e8c48c2a&amp;vg=e1a15b4b-ad83-4b2b-5704-364d06783bc8&amp;pti=9&amp;pa=content&amp;hpi=775&amp;astn1=Popular&amp;rti=2&am

我正在尝试使用可在selenium中使用的xpath/css表达式从以下锚定标记中提取/store href属性。你能帮我点灯吗

<a href="http://domain/bang?a=3681fd26e8c48c2a&amp;vg=e1a15b4b-ad83-4b2b-5704-364d06783bc8&amp;pti=9&amp;pa=content&amp;hpi=775&amp;astn1=Popular&amp;rti=2&amp;u=&amp;1uguid1=19c01b00-ad83-4b2b-3832-674ce2bc1be3&amp;s=206A-0A68-603D-F35D-06C61CFAE18E&amp;pg=-1&amp;p=10215323&amp;ct=http%3A%2F%2Fwww.xyz.com%2FBass-Pro-Shops-The-Hunt-Trophy-Showdown-Video-Game-for-Wii%2Fproduct%2F10215323%2F230625%3FcmCat%3DCROSSSELL_HOMEPAGE">Bass Pro Shops&reg; The Hunt Trophy...</a>

对于Java,您可以这样做

WebElement element = driver.findElement(By.linkPartialText("Bass Pro Shops"));
var thisLink = element.getAttribute("href");

要确定CssSelector或Xpath,我们需要看到更多的代码,而不仅仅是锚元素。理想的做法是使用ID,然后使用ID到锚定标记的元素的所有子元素

你的问题到底是什么?我正在尝试创建xpath,允许我将此链接存储到java中的某个局部变量中。这不是每个基本的“java中的xpath”教程都会介绍的吗?考虑到选择
元素是一项极其琐碎的任务?这是上述锚定的完整html//div[3]/div[5]/div/div/div[2]/table/tbody/tr/td[2]/div/table/tbody/tr/td/aAlso,我没有使用webdriver。当前正在使用selenium网格1//td[@id='myid']//a@href上面的xpath帮助我得到了我需要的东西。谢谢你们插话。