android– 无法在Selenium中使用click()和移动模拟chromedriver

android– 无法在Selenium中使用click()和移动模拟chromedriver,第1张

概述我正在尝试使用移动模拟Chrome浏览器测试内部Web应用程序的登录过程.我使用的是Python3.6.4.它按名称查找元素,但不会单击它!这是我的代码:fromseleniumimportwebdriverentercodeherefromselenium.webdriver.chrome.optionsimportOptionsfromselenium.webdriver.comm

我正在尝试使用移动模拟Chrome浏览器测试内部Web应用程序的登录过程.我使用的是Python 3.6.4.

它按名称查找元素,但不会单击它!

这是我的代码:

from selenium import webdriverenter code herefrom selenium.webdriver.Chrome.options import Optionsfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver.support.ui import Selectimport timemobile_emulation = {    "deviceMetrics": { "wIDth": 360, "height": 640, "pixelRatio": 3.0 },    "userAgent": "Mozilla/5.0 (linux; AndroID 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }Chrome_options = Options()Chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)driver = webdriver.Chrome(Chrome_options = Chrome_options)driver.get("https://internalweburlhere")elem = driver.find_element_by_ID("txtEmailAddress")elem.clear()elem.send_keys("Username")elem = driver.find_element_by_ID("txtPassword")elem.send_keys("1234")print("Password Entered")driver.find_element_by_ID("btnSignIn").click()print("Logged In")

这是网站的来源:

<div ID="divSignIn"  ><div ID="divSignInheader"  MandatoryFIEld="False">Sign in using your Portal account</div><div ID="divSignInMessage"  MandatoryFIEld="False" >Your account email address has Now been verifIEd, please enter your password and sign in</div><div ID="upSignIn"><div ID="divSignInEmailAddress"><div ID="lblEmailAddress" >Enter your email address</div><div><input name="txtEmailAddress" type="email" ID="txtEmailAddress" aria-autocomplete="none" autocomplete="off" maxlength="50"  onkeyup="checkSignInbutton()" /></div></div><div ID="divPassword"><div ID="lblPassword"  MandatoryFIEld="False">Enter your password</div><div><input name="txtPassword" type="password" ID="txtPassword" aria-autocomplete="none" autocomplete="off"  onkeypress="checkCapsLockStatus(event,&#39;divSignInCapsLock&#39;)" onblur="hIDeCapsLockStatus(&#39;divSignInCapsLock&#39;)" onkeyup="checkSignInbutton()" /><div ID="divSignInCapsLock" ><div ID="divCapsLockDetail"><img src="/Portal_Benchmark/Static/5.8.0.192/Images/dlg_icon_Exclamation.png"  /><span ID="lblCapsLockMessage"  MandatoryFIEld="False">Caps Lock Is On</span></div></div></div></div><div ID="divSignInCaptcha" ><div ID="lblSignInCaptcha" >Enter the captcha text shown below </div><input type="hIDden" ID="obJsignInCaptcha_clIEntState" name="obJsignInCaptcha_clIEntState" /><div ID="obJsignInCaptcha" ><div ><img src="WebCaptchaimage.axd?guID=588a4174-70ca-4bf6-ac10-7ac77f74e6a4" title="" alt="" height="60" wIDth="175"  /><input type="hIDden" ID="obJsignInCaptcha__SignInEditor_clIEntState" name="obJsignInCaptcha__SignInEditor_clIEntState" /><input title="{0}" ID="obJsignInCaptcha__SignInEditor" aria-autocomplete="none" autocomplete="off" onkeyup="checkSignInbutton()" Readonly="Readonly" name="obJsignInCaptcha__SignInEditor" maxlength="8"  type="text"  /></div><div ><a href="WebCaptchaimage.axd?guID=588a4174-70ca-4bf6-ac10-7ac77f74e6a4&amp;audio=true"><img alt="Listen to Captcha Audio" ID="x:1812979435.0:mkr:Audiobutton" src="Static/5.8.0.192/PortalStyleSheets/Infragistics/Default/images/igc_Audiobutton.gif" /></a><a ID="x:1812979435.1:mkr:Refreshbuttonlink" href="#"><img alt="Refresh Captcha Image" ID="x:1812979435.2:mkr:Refreshbutton" src="Static/5.8.0.192/PortalStyleSheets/Infragistics/Default/images/igc_Refreshbutton.gif" /></a></div><div ></div></div></div><div ><div ID="lblError" ></div><div ><input name="btnSignIn" type="submit" ID="btnSignIn" Disabled="Disabled" value="Sign In" /></div></div></div>

任何人都可以建议我如何解决这个问题?有趣的是,当我在AndroID Chrome浏览器上的browserstack上运行类似的代码时,点击按预期工作.只是当我在本地运行时.

解决方法:

DOM中存在一些时间元素但是selenium无法等到属性被删除.可能的猜测是在你的情况下它不是等待你的输入标签中删除属性Disabled =“Disabled”并执行点击,即使你看不到任何异常.

因此,在这种情况下,您必须在浏览器中注入JavaScript并执行以下 *** 作:

element = driver.find_element_by_ID("btnSignIn")driver.execute_script('arguments[0].click();', element)
总结

以上是内存溢出为你收集整理的android – 无法在Selenium中使用click()和移动模拟chromedriver全部内容,希望文章能够帮你解决android – 无法在Selenium中使用click()和移动模拟chromedriver所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1118515.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存