2016-01-20 46 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() 
相關問題