Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.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
如何在python中选中没有id的单选框_Python_Selenium_Button - Fatal编程技术网

如何在python中选中没有id的单选框

如何在python中选中没有id的单选框,python,selenium,button,Python,Selenium,Button,我正在用python和selenium编写一段代码,在站点上单击几个按钮。对于大多数按钮,我可以使用类或ID来单击它,但对于单选框,它不起作用。我看了好几个教程,但都不管用。有人能帮我吗?我要单击的代码部分如下: <div class="paycontainer"><div class="payselect" onclick="wishlist_klantinfo(&quot;&quot;, {action:&a

我正在用python和selenium编写一段代码,在站点上单击几个按钮。对于大多数按钮,我可以使用类或ID来单击它,但对于单选框,它不起作用。我看了好几个教程,但都不管用。有人能帮我吗?我要单击的代码部分如下:

<div class="paycontainer"><div class="payselect" onclick="wishlist_klantinfo(&quot;&quot;, {action:&quot;update&quot;,id:&quot;betaaltype_payid&quot;,val:18})">  <input type="radio" name="betaalmethode" value="18"></div><div class="paylogo" onclick="wishlist_klantinfo(&quot;&quot;, {action:&quot;update&quot;,id:&quot;betaaltype_payid&quot;,val:18})">  <img src="/templates/basic/images/pay/pay_18.png"></div><div class="paytitle" onclick="wishlist_klantinfo(&quot;&quot;, {action:&quot;update&quot;,id:&quot;betaaltype_payid&quot;,val:18})">  PayPal <br>(1.5%)</div><div class="payextrafields wl_hidden"></div></div>
贝宝(1.5%)
该HTML示例中有多个元素,您要单击哪一个

支付选择

driver.find_element_by_xpath("//div[@class='payselect']").click()
driver.find_element_by_xpath("//div[@class='paylogo']").click()
driver.find_element_by_xpath("//div[@class='paytitle']").click()

paylogo

driver.find_element_by_xpath("//div[@class='payselect']").click()
driver.find_element_by_xpath("//div[@class='paylogo']").click()
driver.find_element_by_xpath("//div[@class='paytitle']").click()

支付标题

driver.find_element_by_xpath("//div[@class='payselect']").click()
driver.find_element_by_xpath("//div[@class='paylogo']").click()
driver.find_element_by_xpath("//div[@class='paytitle']").click()


共享您尝试过的相关HTML和代码,如果有,请尝试使用xpath而不是id@YevheniiChykalov:你能解释一下为什么有人更喜欢xpath而不是ID吗?@cruisepandey这只是口味的问题。有时,如果DOM元素包含动态属性值,XPATH会有所帮助。我尝试了几种方式,例如:WebElement radio1=driver.findElement(By.id(“betaaltype_payid”)),但这也不起作用。我尝试将值更改为正确的框,但我认为这不是检查它的方法。抱歉,我是python新手,所以可能会问一个愚蠢的问题。问题是这些变量在网站上多次出现,所以它会给出一个错误。唯一不同的是收音机的价值