Python/Selenium按类名称查找元素

2024-09-28 23:21:38 发布

您现在位置:Python中文网/ 问答频道 /正文

硒的基本问题。在

我正在尝试迭代站点中的一个类(没有id,没有名称),但是类名非常长,比如class="my really long crappy class name with space"

我正在尝试mydriver.find_elements_by_class_name(idClass);,其中mydriver = webdriver.Firefox()。在

我也尝试了my.really.long.crappy.class.name.with.space,但这也不起作用(把它看作是对其他问题的解答,比如我)。当我运行这个,我没有得到一个错误,但我的结果是大小为零。在

下面的函数是我当前使用的,我正在打印

        def getElementByClass(idClass):
            a=[];
            try:
                print idClass;
                a = mydriver.find_elements_by_class_name(idClass);
                return a;
            except:
                print 'crap';

Tags: nameby站点mywithspaceelementsfind
1条回答
网友
1楼 · 发布于 2024-09-28 23:21:38

您可以使用^{}

mydriver.find_elements_by_css_selector('.class1.class2.class3');

其中class1class2class3是元素的类名。在

或者,另一个选择是使用^{}

^{pr2}$

如果事先知道标记名,也可以将*替换为它。在

希望有帮助。在

相关问题 更多 >