[英]Is it possible to get source code when making a request with selenium?
There's an element on the website that I am trying to mess around with, but getting to that element is hard, because the ID of it changes every time you visit the page.网站上有一个元素,我想弄乱它,但要访问该元素很困难,因为每次访问该页面时它的 ID 都会更改。
So, I somehow want to get source code whenever selenium enters the website and use regex to get the correct ID of that element.所以,我想在 selenium 进入网站时获取源代码并使用正则表达式来获取该元素的正确 ID。
Any ideas on how to do this?关于如何做到这一点的任何想法? Or any ideas how to get the wanted element in another way?
或者任何想法如何以另一种方式获得想要的元素?
<select role="listbox" aria-required="true" aria-labelledby="label-agreement" class="x-form-text x-form-field " name="agreement" tabindex="0" id="tts-6535350604697758">
<option value=""></option>
<option value="1">I agree</option>
<option value="2">I don't agree</option>
</select>
You can use the name
attribute, it seem unique enough你可以使用
name
属性,它看起来足够独特
driver.find_element_by_name('agreement')
Or by aria-labelledby
attribute或者通过
aria-labelledby
属性
driver.find_element_by_css_selector('[aria-labelledby="label-agreement"]')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.