接受使用硒的不和谐邀请
我正在尝试创建一个简单的脚本来接受Discord邀请。我已经设法登录到一个帐户,但是我无法接受邀请。
我已经尝试使用XPath同样使用CSS选择器来尝试找到按钮,但是我没有运气(下面看到的示例)。
browser.find_element_by_xpath("/html/body/div[1]/div[2]/div/div/div/div/section/div/button")
browser.find_element_by_class_name('marginTop40-i-78cZ.button-3k0cO7.button-38aScr.lookFilled-1Gx00P.colorBrand-3pXr91.sizeLarge-1vSeWK.fullWidth-1orjjo.grow-q77ONN')
外部HTML是:
<button type="button" class="marginTop40-Q4o1tS button-1cRKG6 button-f2h6uQ lookFilled-yCfaCM colorBrand-I6CyqQ sizeLarge-3mScP9 fullWidth-fJIsjq grow-2sR_-F"><div class="contents-3ca1mk">Accept Invite</div></button>
完整的XPath:
/html/body/div[1]/div[2]/div/div[1]/div/div/div/section/div/button
我已经在页面底部附上了一个Discord邀请链接。
任何帮助都将不胜感激。
I'm trying to create a simple script to accept a Discord Invite. I've managed to login to an account however I cannot get it to accept the invite.
I've tried using the XPath aswell as using CSS selector to try and find the button but i'm having no luck (examples seen below).
browser.find_element_by_xpath("/html/body/div[1]/div[2]/div/div/div/div/section/div/button")
browser.find_element_by_class_name('marginTop40-i-78cZ.button-3k0cO7.button-38aScr.lookFilled-1Gx00P.colorBrand-3pXr91.sizeLarge-1vSeWK.fullWidth-1orjjo.grow-q77ONN')
The outer html is:
<button type="button" class="marginTop40-Q4o1tS button-1cRKG6 button-f2h6uQ lookFilled-yCfaCM colorBrand-I6CyqQ sizeLarge-3mScP9 fullWidth-fJIsjq grow-2sR_-F"><div class="contents-3ca1mk">Accept Invite</div></button>
Full XPath:
/html/body/div[1]/div[2]/div/div[1]/div/div/div/section/div/button
I've attached a discord invite link at the bottom of the page as an example.
Any help would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所需元素是动态元素,因此要单击您需要诱导的元素 webdriverwait href =“ https://stackoverflow.com/a/54194511/7429447”> emeltage_be_be_clickable() ,您可以使用以下任何一个 定位器策略 :
使用 css_selector :
使用 xpath :
注意:您必须添加以下导入:
The desired element is a dynamic element, so to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
Using XPATH:
Note: You have to add the following imports :