Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium Python无法在ConnectWise登录页面上选择元素_Python_Html_Selenium - Fatal编程技术网

Selenium Python无法在ConnectWise登录页面上选择元素

Selenium Python无法在ConnectWise登录页面上选择元素,python,html,selenium,Python,Html,Selenium,您好,我正在尝试选择Connectwise登录页面上的公司框以自动登录 然而,我甚至在选择公司领域都有困难 需要选择的元素: <input class="loginTextBox loginTextBox-watermark" type="text" autocomplete="off" autocorrect="off" autocapitalize="off"/> 堆栈跟踪: selenium.common.exceptions.InvalidSelectorExceptio

您好,我正在尝试选择Connectwise登录页面上的公司框以自动登录

然而,我甚至在选择公司领域都有困难

需要选择的元素

<input class="loginTextBox loginTextBox-watermark" type="text" autocomplete="off" autocorrect="off" autocapitalize="off"/>
堆栈跟踪:

selenium.common.exceptions.InvalidSelectorException:Message:invalid选择器:找不到xpath表达式为/x:html/x:body/x:div/x:table/x:tbody/x:tr/x:table/x:tbody/x:tr[2]/x:td/x:table/x:tbody/x:tr/x:td/x:table/x:tbody/x:tbody/x:tr/x:tr/x:td/x:td/x:tbody/x:td/x:table/x:tr/x:td/x:td/x:td/x:

已尝试类选择

company_field = driver.find_element_by_xpath("/x:html/x:body/x:div[6]/x:div/x:table/x:tbody/x:tr[1]/x:td/x:table/x:tbody/x:tr[2]/x:td/x:table/x:tbody/x:tr[1]/x:td/x:table/x:tbody/x:tr/x:td[2]/x:table/x:tbody/x:tr[1]/x:td/x:input")
company_field = driver.find_element_by_class_name("loginTextBox loginTextBox-watermark")
堆栈跟踪:

selenium.common.exceptions.InvalidSelectorException:消息:无效选择器:不允许使用复合类名

已尝试CSS

driver.find_element_by_css_selector(".loginTextBox loginTextBox-watermark[type='text']").click()
堆栈跟踪:

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{“方法”:“css选择器”,“选择器”:.loginTextBox loginTextBox水印[type='text']”

页面的HTML源代码:

<document>
<html>
<head>
<body style="background-color: #F2F2F2; margin: 0px; padding: 0px;" ondragover="window.event.returnValue=false;">
<iframe id="__gwt_historyFrame" style="position:absolute;width:0;height:0;border:0" tabindex="-1" src="javascript:''"/>
<script src="common/scripts/cw.js?v=201561" type="text/javascript"/>
<script src="common/scripts/cw.io.js?v=201561" type="text/javascript"/>
<script language="javascript" type="text/javascript">     function checkSsl() {         if (document.location.protocol != "https:" && document.location.host.indexOf("localhost") == -1 && document.location.href.indexOf("dotnet") == -1) {             cw.io.jsonCall("login/IsSslRequired.rails", { 'onsuccess': function (data) {                 if (data.Data == true) {                     var url = "https://" + document.location.host + document.location.pathname + document.location.search + document.location.hash;                     document.location.href = url;                 }             }              });         }     } cw.ui.createInitialLoadingNode();         checkSsl(); document.writeln("<script type='text/javascript' language='javascript' src='com.connectwise.psa/com.connectwise.psa.nocache.js'></scr" + "ipt>"); function dragover(e) { return false; } </script>
<div id="cw-loading" class="cw-loading">
<script src="com.connectwise.psa/com.connectwise.psa.nocache.js" language="javascript" type="text/javascript"/>
<iframe id="com.connectwise.psa" src="javascript:""" style="position: absolute; width: 0px; height: 0px; border: medium none; left: -1000px; top: -1000px;" tabindex="-1"/>
<div style="display: none;" aria-hidden="true"/>
<div style="position: absolute; z-index: -32767; top: -20cm; width: 10cm; height: 10cm; visibility: hidden;" aria-hidden="true"/>
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div class="GHN3134DCB" style="position: absolute; left: 0px; top: 0px; display: block; width: 1366px; height: 659px;"/>
<div class="GHN3134DJB" style="left: 435px; top: 163px; border-width: 0px; z-index: 555555555; position: absolute; overflow: visible; background-color: transparent;">
<div class="popupContent">
<table cellspacing="0" cellpadding="0" style="">
<tbody>
<tr>
<td align="left" style="vertical-align: top;">
<table class="GHN3134DK5I" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<tr>
<td align="left" style="vertical-align: top;">
<table class="GHN3134DJ5I" cellspacing="0" cellpadding="0" style="display: block;">
<tbody>
<tr>
<td align="left" style="vertical-align: top;">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" style="vertical-align: top;">
<td align="left" style="vertical-align: top;">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="left" style="vertical-align: top;">
<input class="loginTextBox loginTextBox-watermark loginTextBox-hightlight" type="text" autocomplete="off" autocorrect="off" autocapitalize="off"/>
</td>
</tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
</document>

函数checkSsl(){if(document.location.protocol!=“https:&&document.location.host.indexOf(“localhost”)=-1&&document.location.href.indexOf(“dotnet”)=-1){cw.io.jsonCall(“login/IsSslRequired.rails”,“onsuccess”:函数(data){if(data.data==true){var url=“https://”+document.location.host+document.location.pathname+document.location.search+document.location.hash;document.location.href=url;}}}}}}}}}cw.ui.createInitialLoadingNode();checkSsl();文件。书面形式(“”);函数dragover(e){返回false;}
能帮忙吗

谢谢你抽出时间

selenium.common.exceptions.InvalidSelectorException:Message:invalid选择器:找不到xpath表达式为/x:html/x:body/x:div/x:table/x:tbody/x:tr1/x:td/x:table/x:tr[2]/x:td/x:table/x:tbody/x:tr1/x:td/x:td/x:table/x:table/x:tbody/x:tr/x:td/x:td[2]/x:tr1/x:td/x:input

发生此错误的原因是提供的
xpath
语法不正确

selenium.common.exceptions.InvalidSelectorException:消息:无效选择器:不允许使用复合类名

发生此错误是因为selenium不支持复合类来定位元素

selenium.common.exceptions.NoSuchElementException:消息:没有这样的元素:无法定位元素:{“方法”:“css选择器”,“选择器”:.loginTextBox loginTextBox水印[type='text']”

发生此错误是因为您定位的元素不正确。根据定位器,将尝试定位属性<代码>类型<代码>具有值<代码>文本<并且应该是具有不正确的类属性值<代码>loginTextBox的元素的后代的
元素

因此,基本上,您提供的所有定位器在语法或逻辑上都不正确,您应该尝试使用正确的
css\u选择器
定位器,如下所示:-

driver.find_element_by_css_selector("input.loginTextBox.loginTextBox-watermark.loginTextBox-hightlight[type='text']")
或者,如果
类名
GHN3134DJ5I
是唯一且固定的,您还可以尝试以下操作:-

driver.find_element_by_css_selector("table.GHN3134DJ5I input.loginTextBox.loginTextBox-watermark.loginTextBox-hightlight[type='text']")
Css选择器参考:至


Xpath参考::非常感谢您抽出时间来Saurabh!我有很多东西要学。