<div class='navigationbar__header'> <a class='navigationb […]">

如何使用SeleniumPython单击页面顶部导航栏中的项目?

2021-01-08 20点热度 0人点赞 0条评论

我正在尝试使用SeleniumPython测试网页。一切正常,但点击导航栏项目时遇到问题。

我用过:

driver.find_element_by_xpath('./li/a[. = "Log in"]')

还使用了:

driver.find_element_by_link_text('Log in')

没什么好运气的!你看!

代码段:

<div class='container'>
<div class='navigationbar__header'>
<a class='navigationbar__header__logo tracking-link' data-link-name='logo' href='/' target='_self'>
<div id='hired-brand'>HIRED</div>
</a>
</div>
<div class='navigationbar__toggle'>
<div class='navigationbar__toggle__element'>
<img alt='Menu' class='icon icon--sandwich' src='data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'>
</div>
<input class='navigationbar__toggle__helper' type='checkbox'>
<ul class='navigationbar__navigation'>
<li class="navigationbar__item "><a class="sm-ml0 tracking-link" data-link-name="employers_page" target="_self" href="/employers">For Employers</a></li>
<li class="navigationbar__item "><a class="sm-ml0 tracking-link" data-link-name="success_stories" target="_self" href="/success-stories">Success Stories</a></li>
<li class="navigationbar__item "><a class="sm-ml0 tracking-link" data-link-name="employers_resources" target="_self" href="/employers/resources">Resources</a></li>
<li class="navigationbar__item "><a class="text-medium sm-ml0 tracking-link" data-link-name="login" target="_self" href="/login">Log in</a></li>
<div class='xs-ptb1 xs-prl1 md-ptb0 md-inline-block'><li class="navigationbar__item "><a class="button button--primary tracking-link" data-link-name="signup" target="_self" href="/signup">Sign Up</a></li></div>

</ul>
</div>
</div>
</nav>

此代码在页面上可见,易于检查。有人知道更好的互动方式吗?

查看隐藏内容需要支付:¥1
查看

未经允许不得转载!如何使用SeleniumPython单击页面顶部导航栏中的项目?

本文地址:https://ans.52learn.online/2151

ANS52LEARN

DO BEST