2016-01-20 48 views
0

我真的不知道如何说这个标题,但这是我想要做的 所以基本上,我试图让客户端或用户选择他想使用的课程,但我找不到要做到这一点,因为它需要三重报价Python如何用三个引号写入?

from selenium import webdriver 

x = str("\"\"\"") 
y = str("\"\"\"") 
class_name = input("Class name: ") 
driver.get("http://stackoverflow.com/questions/12094153/selenium-webdriver-find-element-by-xpath-on-webelement") 
driver.find_element_by_xpath(x + class_name + y).click() 
+0

我不知道你想与三重引号做什么,但他们只用于文字,这'class_name'是不。我在那里看不到任何'exec'或'eval',所以也没有。这是[XY问题](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)。 – TigerhawkT3

回答

0

为什么不使用find_element_by_css_selector?用xpath寻找具有类的元素需要更多的努力。

driver.find_element_by_css_selector('.' + class_name).click() 

顺便说一句,三重引号字符串与问题无关。

+0

工作,哇我一直在尝试这几个小时现在,谢谢<3,我会看看find_element_by_css_selector – Ghost

+0

好吧,明白了,无论如何将两个功能相乘?这里是什么即时通讯 http://hastebin.com/jitetakuxi.py – Ghost

+0

忽略x =,y = – Ghost

1

保持简单和使用find_element_by_class_name()方法直接:

from selenium import webdriver 

class_name = input("Class name: ") 
driver.get("http://stackoverflow.com/questions/12094153/selenium-webdriver-find-element-by-xpath-on-webelement") 
driver.find_element_by_class_name(class_name).click() 
相关问题