Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.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和selenium中的字符串_Python_Selenium - Fatal编程技术网

如何比较Python和selenium中的字符串

如何比较Python和selenium中的字符串,python,selenium,Python,Selenium,如果我从该元素打印的文本是正确的,则代码将通过它 for items2 in ListaPlajePariuri: NumePlaje = items2.find_element_by_class_name( 'KambiBC-bet-offer-category__title js-bet-offer-category-title') TotalGoluri = items2.

如果我从该元素打印的文本是正确的,则代码将通过它

     for items2 in ListaPlajePariuri:
         NumePlaje = items2.find_element_by_class_name(
                                    'KambiBC-bet-offer-category__title js-bet-offer-category-title')
         TotalGoluri = items2.find_elements_by_class_name(
                                    'KambiBC-bet-offer-subcategory KambiBC-bet-offer-subcategory--overunder')
         print(NumePlaje.text)


         if NumePlaje.text == 'Timp regulamentar' :
             input("why will you not work?")
             NumePlaje.click()
这是一个打印屏幕,输出来自
print(NumePlaje.text)
,看起来不错

如果约翰·戈登表示他想回答,我将撤回这个答案

John Gordon指出变量
NumePlaje.text
可能有尾随空格。在这种情况下,即使变量包含该字符串,对
NumePlaje.text==“Timp regulamentar”
的简单测试也会失败

然后,该字符串是否存在的测试应为:

if 'Timp regulamentar' in NumePlaje.text:

此版本的
if
询问字符串是否出现在变量中的任何位置。

文本是否有尾随空格?试着这样打印:
print('|%s |“%NumePlaje.text)
print屏幕输出很难读取。当您在SO问题中发布文本时,请按照Python代码的方式进行。遵循@JohnGordon的思想,您可以使用
测试该字符串,如果NumePlaje中的'Timp regulamentar'。text:
。这样一来,NumePlaje.text中的其他内容就不重要了。@JohnGordon这是新的输出| Timp regulamentar |,我试图将其与此进行比较,但仍然忽略了它it@BillBell你的建议奏效了,如果你写一个答案,我会接受的,谢谢