单击“使用API查找xpath元素”按钮,或单击“使用API查找xpath元素”

2024-04-19 09:58:34 发布

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

如何选择'开始'按钮,并点击它从下面的HTML代码。 我想使用下面的python-selenium库 比如:

driver.find_element_by_xpath('//div[contains(@class,"box enter")' 
                                         'and text() = "start"]').click()

HTML代码

<section class="LandingPageView shown" style="display: block;">
<div class="background"></div>
<div class="gradient"></div>
<div class="page" style="opacity: 1;">
    <div class="background asset background-homepage"></div>
    <div class="just-reflektor-link" style="width: 312.289575px; height: 381.447127941177px; right: 25.635%;"></div>
    <div class="content" style="right: -14.3125px; margin-left: 0px; transform: scale(1); -webkit-transform: scale(1);">
        <div class="hero-logo"></div>
        <p class="title"><bdo dir="ltr">A virtual projection<br>by Vincent Morisset</bdo></p>
        <button class="box enter" dir="" style="transform: scale(1.001); -webkit-transform: scale(1.001);"><bdo dir="ltr">Start</bdo></button>
        <p class="error-browser other" dir=""><bdo dir="ltr">Your web browser is not <br>supported by this experience. <br>Please try again using <a href="https://www.google.com/chrome">Google Chrome</a>.</bdo></p>
        <p class="error-browser ff" dir=""><bdo dir="ltr">For the best performance, <br>we recommend <a href="https://www.google.com/chrome">Google Chrome</a>.</bdo></p>    
    </div>    
    <div class="link mouse-mode" dir=""><bdo dir="ltr">*No phone? <a>Use your mouse</a>.</bdo></div>
</div>
</section>

Tags: 代码brdivbrowserbystylehtmldir
2条回答

我不擅长xpath,但是为什么不使用css选择器呢?你知道吗

driver.find_element_by_css_selector('button.box.enter').click()

下面是如何通过XAPTH找到元素。你知道吗

element = driver.find_element_by_xpath('//button[@class="box enter" and contains(.,"Start")]')
element.click()

相关问题 更多 >