Javascript Python selenium a标记不包含href,链接仅在单击时生成
我正在尝试自动测试网站()。这个网站有一个名字列表(如下所示),如果我点击每个名字,它会将我发送到一个不同的页面,在那里它存储了这些信息,但是Javascript Python selenium a标记不包含href,链接仅在单击时生成,javascript,jquery,python,html,selenium,Javascript,Jquery,Python,Html,Selenium,我正在尝试自动测试网站()。这个网站有一个名字列表(如下所示),如果我点击每个名字,它会将我发送到一个不同的页面,在那里它存储了这些信息,但是 如你所见,如果我点击 以下是我迄今为止通过Selenium实现的目标: #storing the url so after going to different url it needs to come back and click to the next element url = driver.current_url #Gettin
如你所见,如果我点击
以下是我迄今为止通过Selenium实现的目标:
#storing the url so after going to different url it needs to come back and click to the next element
url = driver.current_url
#Getting each agent element list
for attr in driver.find_elements_by_xpath('.//*[@class="agent"]'):
#visiting the page again to make list of persons visible again
driver.get(url)
#clicking on each of then hence visiting them
attr.find_element_by_xpath('.//*[@class="info"]/h1/a').click()
但正如所怀疑的那样,如果有办法获取链接,或者访问名称列表中的每个链接,那么该代码就不起作用了
最后但并非最不重要的是,这里是代理类div
的HTML(图片中代理的HTML):
总理
代理人
这个人的名字在这里
先锋地产代理
没有评论
18
出售
2358万美元
家常装上的
目前,这个问题对我来说仍然很难理解,没有令人讨厌的格式。您只想单击并导航到显示的所有代理,对吗?是的,但标记不包含任何链接,因此我必须单击它们,但当我单击它们时,旧页面将消失(我访问代理信息页面),我必须返回旧页面以使代理再次访问。新选项卡是否可以更好地打开每个代理。。当代理的另一个页面停留在那里时,不用担心,即使你的日程安排很忙,你也在试图帮助互联网上的某个随机的家伙。。我很感激,再次感谢
<div class="agent">
<div class="pic">
<a>
<img class="img-circle hoverZoomLink" src="//res-1.cloudinary.com/hd1n2hd4y/image/upload/f_auto,q_auto,c_fill,w_150,h_150,g_face,dpr_1.0/user-default.jpg">
</a>
<label class="premier-label hide">
<!-- react-text: 178 -->Premier
<!-- /react-text -->
<span class="agent-text">Agent</span>
</label>
</div>
<div class="info">
<h1>
<a>THE NAME OF THE PERSON GOES HERE</a>
</h1>
<p class="company">Vanguarde Estate Agents</p>
<div class="Rating">
<span role="presentation" class="icon-wrapper">
<svg class="icon icon-star-outline-medium">
<use
xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-star-outline-medium">
</use>
</svg>
</span>
<span role="presentation" class="icon-wrapper">
<svg class="icon icon-star-outline-medium">
<use
xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-star-outline-medium">
</use>
</svg>
</span>
<span role="presentation" class="icon-wrapper">
<svg class="icon icon-star-outline-medium">
<use
xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-star-outline-medium">
</use>
</svg>
</span>
<span role="presentation" class="icon-wrapper">
<svg class="icon icon-star-outline-medium">
<use
xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-star-outline-medium">
</use>
</svg>
</span>
<span role="presentation" class="icon-wrapper">
<svg class="icon icon-star-outline-medium">
<use
xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-star-outline-medium">
</use>
</svg>
</span>
<span class="Rating-label">No reviews</span>
</div>
<p class="recommendation hide"></p>
<!-- react-empty: 192 -->
</div>
<div class="total-listings-info">
<p class="total-listings">
<!-- react-text: 195 -->18
<!-- /react-text -->
<!-- react-text: 196 -->
<!-- /react-text -->
<!-- react-text: 197 -->sold
<!-- /react-text -->
</p>
<p class="message">
<!-- react-text: 199 -->in
<!-- /react-text -->
<!-- react-text: 200 -->Sydney (CBD)
<!-- /react-text -->
</p>
<p class="message">
<!-- react-text: 202 -->past
<!-- /react-text -->
<!-- react-text: 203 -->12
<!-- /react-text -->
<!-- react-text: 204 --> months
<!-- /react-text -->
</p>
</div>
<div class="listings-value-info hide">
<p class="value">$23.58m</p>
<p class="message">listed sold value</p>
<p class="message">on Homely</p>
</div>
<div class="office-bar hide" style="background: rgb(241, 241, 241);">
<img src="//res-4.cloudinary.com/hd1n2hd4y/image/upload/f_auto,q_auto,c_fill,h_30,dpr_1.0/v1430193584/franchiselogo-14883.jpg">
</div>
</div>