请帮助我,因为我是Python Selenium的新手。我正在使用Anaconda2,Jupiter和Chrome浏览器。
我正在编写成功运行的代码,但现在我想点击按钮。
<a href="#" action="exportSelected" class="btn btn-default">
<i class="glyphicon glyphicon-download"></i> Export
</a>
我应该用Python写什么来访问它?请帮忙。驱动程序。
find_element_by_partial_link_text('btn btn-default').click()
这是错误的。
请建议......先谢谢您的宝贵时间!
Harish Kumar答案 0 :(得分:5)
[Code]
var
WelcomePage: TOutputMsgMemoWizardPage;
procedure InitializeWizard();
var
WelcomeFileName: string;
WelcomeFilePath: string;
begin
{ Create welcome page, with the same labels as the information page }
WelcomePage :=
CreateOutputMsgMemoPage(
wpWelcome, SetupMessage(msgWizardInfoBefore), SetupMessage(msgInfoBeforeLabel),
SetupMessage(msgInfoBeforeClickLabel), '');
{ Load welcome page }
WelcomeFileName := '{#WelcomeFile}';
ExtractTemporaryFile(WelcomeFileName);
WelcomeFilePath := ExpandConstant('{tmp}\' + WelcomeFileName);
WelcomePage.RichEditViewer.Lines.LoadFromFile(WelcomeFilePath);
DeleteFile(WelcomeFilePath);
end;
不是链接文字,而是类名。
您可以使用以下解决方案之一:
按完全链接文字找到:
"btn btn-default"
按复合类名称定位:
find_element_by_link_text('Export').click()
按find_element_by_css_selector('a.btn.btn-default').click()
属性
action
答案 1 :(得分:0)
谢谢大家回复我并建议pyhthon doc。欣赏它。
所以我用非常简单的线条完成了我的工作。
driver.find_element_by_xpath(&#39;复制你的xpath&#39;)。 这很简单
driver.find_element_by_xpath(&#39; // [@ ID =&#34; app_content&#34;] / DIV [2] / DIV / DIV /部分/ DIV / DIV [2] /格[ 1] / DIV [1] / DIV / DIV [2] / A [1]&#39;。)点击() driver.implicitly_wait(5) driver.find_element_by_xpath(&#39; // [@ ID =&#34; export_button&#34;]&#39)。单击()