【问题标题】:Requiring line of code to select nature of payment from drop down list需要代码行从下拉列表中选择付款性质
【发布时间】:2020-02-06 17:21:38
【问题描述】:

我遵守了下面提到的代码行,但它不起作用。我不知道如何选择付款性质,付款性质标签在附图中的箭头之间标记。

Sub TDS_Autofill()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://onlineservices.tin.egov-nsdl.com/etaxnew/tdsnontds.jsp"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop

Set doc = IE.document

doc.parentWindow.execScript "sendRequest(281)", "JavaScript"

Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop


If ThisWorkbook.Sheets("Challan AutoFill").Range("m2").Value = "Company" 
Then
doc.getElementById("0020").Click
ElseIf ThisWorkbook.Sheets("Challan AutoFill").Range("m2").Value = "Non 
Company" Then
doc.getElementById("0021").Click
End If



If ThisWorkbook.Sheets("Challan AutoFill").Range("o2").Value = "(200) 
TDS/TCS Payable by Taxpayer" Then
doc.getElementById("200").Click
ElseIf ThisWorkbook.Sheets("Challan AutoFill").Range("o2").Value = "(400) 
TDS/TCS Regular Assessment" Then
doc.getElementById("400").Click
End If

doc.getElementsByName("NaturePayment").Value = ThisWorkbook.Sheets("Challan 
AutoFill").Range("q2").Value



End Sub

【问题讨论】:

  • 我的代码的最后一行不起作用。
  • 当它不工作时你会收到错误吗?还是只是没有改变?
  • 我收到错误 - 运行时错误“438”:对象不支持此属性或方法。

标签: html excel vba web-scraping automation


【解决方案1】:

您可以在select 本身上使用selectedIndex,然后在该选择下的列表中指定感兴趣的选项索引。我

ie.document.querySelector("select.form-control").SelectedIndex = 2 '3 or 3 etc....

或者

在选项元素本身上使用.Selected = True,例如

ie.document.querySelector("[value='193 - Interest on Securities']").Selected = True

【讨论】:

  • 这工作正常,但我在给定的网站上还有一个名为 Assessment Year 的 select.form-control,我该怎么办?
【解决方案2】:

getElementsByName 方法返回一个元素数组,即使只有一个具有该名称的元素。您必须改用getElementsByName("NaturePayment")(0).Value

【讨论】:

  • 它不工作,但我现在没有收到任何错误。
  • 在检查元素时,这是我获得的付款性质选项卡代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-07
  • 1970-01-01
  • 2018-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多