Python | Selenium无法检测按钮

Python | Selenium无法检测按钮,python,html,css,selenium,Python,Html,Css,Selenium,这是代码。它应该打开一个chrome浏览器并导航到Kahoot.it网站。然后把你提供的信息记录下来,为你输入。它适用于进入游戏的第一部分,但一旦它创建了你的昵称,它就无法检测到OK,go!按钮 from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.keys import Keys from selenium.web

这是代码。它应该打开一个chrome浏览器并导航到Kahoot.it网站。然后把你提供的信息记录下来,为你输入。它适用于进入游戏的第一部分,但一旦它创建了你的昵称,它就无法检测到OK,go!按钮

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
import os

Game_Pin = input('Enter your PIN: ')
NickNAME = input('Enter your nickname: ')
driver = webdriver.Chrome(executable_path=r"C:\WebDriver\bin\chromedriver.exe")

def Enter_Press(driver):
    driver.find_element_by_xpath("//*[contains(text(), 'Enter')]").click()

def OK_GO(driver):
    driver.find_element_by_xpath("//*[contains(text(), 'OK, go!')]").click()


def Kahoot_Spammer(Game_Pin, NickNAME, driver):
    driver.get('https://kahoot.it/')
    driver.maximize_window() #For maximizing window
    driver.implicitly_wait(2) #gives an implicit wait for 2 seconds

    game_pin = driver.find_element_by_xpath("//*[@id='inputSession']")
    game_pin.send_keys(Game_Pin)
    Enter_Press(driver)

    driver.implicitly_wait(2)
    Name = driver.find_element_by_xpath("//*[@id='username']")
    Name.send_keys(NickNAME)
    OK_GO(driver)




Kahoot_Spammer(Game_Pin, NickNAME, driver)
我已经检查了按钮,但似乎无法在上面的代码中找到要放置的内容。有什么想法吗

这是源代码

driver.find_element_by_xpath("//*[contains(text(), 'OK, go!')]").click()

卡胡特!
(函数(e,t){var n=e.amplitude{u q:[],{u iq:{}};var r=t.createElement(“脚本”);r.type=“text/javascript”;
r、 async=true;r.src=”https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-3.4.0-min.gz.js";
r、 onload=function(){e.amplium.runQueuedFunctions()};var i=t.getElementsByTagName(“脚本”)[0];
i、 parentNode.insertBefore(r,i);函数s(e,t){e.prototype[t]=function(){this.\u q.push([t].concat(Array.prototype.slice.call(arguments,0));
返回此}var o=function(){this.\u q=[];返回此};var a=[“添加”、“追加”、“清除所有”、“预结束”、“设置”、“设置一次”、“取消设置”];
对于(var u=0;u
  • 确保你有足够的时间
  • 关闭或禁用NoScript扩展(如果有)
  • 请与您的IT管理员联系,以允许访问您的安全首选项中的Kahoot
  • 如果您仍然有问题,请让我们知道

    加入Kahoot!来 要了解有关Kahoot的更多信息,请访问

    (函数(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]| |函数(){ (i[r].q=i[r].q | |[]).push(参数)},i[r].l=1*新日期();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(窗口,文档,“脚本”,“www.google-analytics.com/analytics.js”,“ga”); 函数gup(名称、url){ 如果(!url)url=location.href; 名称=名称。替换(/[\[]/,“\\\[”)。替换(/[\]]/,“\\\]”); var regexS=“[\\?&]”+name+“=([^&\\]*)”; var regex=新的RegExp(regexS); var results=regex.exec(url); 返回结果==null?null:结果[1]; } var clientId=gup('gaId',window.location.search); 如果(客户ID){ ga('create','UA-35308575-1','auto',{'allowLinker':true,'clientId':gup('gaId',window.location.search)}); ga('create','UA-35308575-4','auto',{'name':'legacy','clientId':gup('gaId',window.location.search)}); var platform=gup('platform',window.location.search); 如果(平台类型=='string'&&platform=='iOS'){ ga('set','appName','Kahoot'); ga('set','appId','no.mobitroll.kahoot.controller'); } 如果(平台类型=='string'&&platform=='Android'){ ga('set','appName','Kahoot'); ga('set','appId','no.mobitroll.kahoot.android'); } }否则{ ga('create','UA-35308575-1','auto',{'allowLinker':true}); ga('create'、'UA-35308575-4'、'auto'、{'name':'legacy'}); } ga(‘发送’、‘页面浏览’); ga('legacy.send','pageview');
    隐式\u wait
    在初始化
    驱动程序时只需声明一次。要显式等待指定的秒数,可以使用
    time.sleep()
    ,尽管更实用的解决方案是使用Selenium动态等待元素出现/可点击。

    这不是
    隐式等待的工作方式。在您的情况下,最好使用
    时间。睡眠
    
    
    <!doctype html>
    <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
    <!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
    <!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
    <!--[if IE 9]>    <html class="no-js lt-ie10" lang="en"> <![endif]-->
    <!--[if gt IE 9]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    
      <title>Kahoot!</title>
      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, minimum-scale=1.0"/>
      <meta name="viewport" content="initial-scale=1, maximum-scale=1.0, minimum-scale=1.0" media="(device-height: 568px)"/>
      <meta name="apple-mobile-web-app-capable" content="yes" />
      <meta name="apple-itunes-app" content="app-id=1131203560">
    
      <meta name="description" content="Join a game of kahoot here. Kahoot! is a free game-based learning platform that makes it fun to learn – any subject, in any language, on any device, for all ages!">
      <meta name="keywords" content="education, platform, smart phone, tablet, mobile, social, inclusive, HTML5, classroom, engagement, play, game, fun, quiz, multi-player, pedagogy, learning model, learn, gamification." />
    
    
      <link rel="shortcut icon" href="/shared/theme/kahoot/img/icons/favicon.ico">
      <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/shared/theme/kahoot/img/icons/touch_icon_144.png">
      <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/shared/theme/kahoot/img/icons/touch_icon_114.png">
      <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/shared/theme/kahoot/img/icons/touch_icon_72.png">
      <link rel="apple-touch-icon-precomposed" href="/shared/theme/kahoot/img/icons/touch_icon_57.png">
    
      <link rel="stylesheet" type="text/css" href="/shared/css/cloak.css">
    
      <div style="height: 0; width: 0; position: absolute; visibility: hidden">
        <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><filter x="-2.2%" y="-2.3%" width="104.4%" height="104.8%" filterUnits="objectBoundingBox" id="a"><feOffset dy="1" in="SourceAlpha" result="shadowOffsetOuter1"/><symbol id="logo-shapes" viewBox="0 0 24 24"><ellipse cx="5.506" cy="18.966" rx="4.953" ry="4.953"/><path d="M12.005 5.902L17.873.033l5.869 5.869-5.869 5.868zm1.443 8.899h8.849v8.849h-8.849zm-2.584-4.977H.146l5.36-8.555z"/></symbol></svg>
      </div>
    
      <script src="https://tap-nexus.appspot.com/js/sdk/kahunaAPI_min.js"></script>
    
      <script type="text/javascript">
        (function(e,t){var n=e.amplitude||{_q:[],_iq:{}};var r=t.createElement("script");r.type="text/javascript";
        r.async=true;r.src="https://d24n15hnbwhuhn.cloudfront.net/libs/amplitude-3.4.0-min.gz.js";
        r.onload=function(){e.amplitude.runQueuedFunctions()};var i=t.getElementsByTagName("script")[0];
        i.parentNode.insertBefore(r,i);function s(e,t){e.prototype[t]=function(){this._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
        return this}}var o=function(){this._q=[];return this};var a=["add","append","clearAll","prepend","set","setOnce","unset"];
        for(var u=0;u<a.length;u++){s(o,a[u])}n.Identify=o;var c=function(){this._q=[];return this;
        };var p=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"];
        for(var l=0;l<p.length;l++){s(c,p[l])}n.Revenue=c;var d=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties","setGroup","logRevenueV2","regenerateDeviceId","logEventWithTimestamp","logEventWithGroups"];
        function v(e){function t(t){e[t]=function(){e._q.push([t].concat(Array.prototype.slice.call(arguments,0)));
        }}for(var n=0;n<d.length;n++){t(d[n])}}v(n);n.getInstance=function(e){e=(!e||e.length===0?"$default_instance":e).toLowerCase();
        if(!n._iq.hasOwnProperty(e)){n._iq[e]={_q:[]};v(n._iq[e])}return n._iq[e]};e.amplitude=n;
        })(window,document);
      </script>
    
      <base href="/">
    
      <script type="text/javascript">
        document.write('<scri'+'pt ');
        document.write('type="text/javascript" ');
        document.write('src="'+'/shared/theme/config.js');
        document.write("?"+new Date().getTime()+'">');
        document.write('</scri'+'pt>');
      </script>
    </head>
    <body snitch ios7-viewport-fix>
      <noscript>
        <h1>Kahoot! needs JavaScript to work</h1>
    
        <p>
          To use Kahoot!, you need to have JavaScript enabled in your browser. To enable JavaScript, please do the following:
        </p>
         <ul>
          <li><a href="http://enable-javascript.com/">Follow these instructions</a>.</li>
          <li>Make sure you have the <a href="https://www.mozilla.org/en-US/firefox/new/">latest browser</a>.</li>
          <li>Turn off or disable the NoScript extension, if you have it.</li>
          <li>Contact your IT administrator to allow access to Kahoot! in your security preferences.</li>
        </ul>
    
        <p>If you continue to have problems, please let us know by <a href="http://kahoot.uservoice.com/">contacting Kahoot! support</a>.</p>
      </noscript>
      <div id="debug-info" debug-info="dev,test" debug-timestamp></div>
      <dev-mode></dev-mode>
    
      <div class="loader" loader></div>
    
      <iframe
        id="gameBlockIframe"
        style="display:none;"
        class="game-block-iframe"
        sandbox="allow-scripts allow-same-origin"
        scrolling="no">
      </iframe>
    
      <div id="mainView" ng-cloak ng-view>
        <h1>Join in a Kahoot! here</h1>
        <p>To learn more about Kahoot! visit <a href="https://kahoot.com/?utm_source=controller&utm_campaign=controller_app" target="_system">kahoot.com</a></p>
      </div>
    
      <div ng-cloak alerts></div>
    
      <script type="text/javascript" src="/js/bootstrap.js"></script>
      <script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
        (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
    
    function gup( name, url ) {
        if (!url) url = location.href;
        name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regexS = "[\\?&]"+name+"=([^&#]*)";
        var regex = new RegExp( regexS );
        var results = regex.exec( url );
        return results == null ? null : results[1];
    }
    
    
    
    var clientId = gup('gaId', window.location.search);
    
    if (clientId) {
      ga('create', 'UA-35308575-1', 'auto', {'allowLinker': true, 'clientId':gup('gaId', window.location.search)});
      ga('create', 'UA-35308575-4', 'auto', {'name': 'legacy', 'clientId':gup('gaId', window.location.search)});
      var platform = gup('platform', window.location.search);
    
      if (typeof platform === 'string' && platform == 'iOS') {
              window.ga('set', 'appName', 'Kahoot');
              window.ga('set', 'appId', 'no.mobitroll.kahoot.controller');
            }
      if (typeof platform === 'string' && platform == 'Android') {
              window.ga('set', 'appName', 'Kahoot');
              window.ga('set', 'appId', 'no.mobitroll.kahoot.android');
            }
    } else {
      ga('create', 'UA-35308575-1', 'auto', {'allowLinker': true});
      ga('create', 'UA-35308575-4', 'auto', {'name': 'legacy'});
    }
    
    
      ga('send', 'pageview');
      ga('legacy.send', 'pageview');
    
      </script>
    
    </body>
    </html>